JavaScript - How To Use Offsetwidth
i have doen flag animation but it has fix width.. i want it to be offsetWidth so no mater wht browser is it bounce back from end.. and my stop button is not working.. it works in 1st but as i use start button twice stop button dont work.. plz help me
Code: <script language="JavaScript" type="text/javascript"> <!-- function flagMove() { var obj = document.getElementById('float'); if (!obj) return false; var leftPos = parseInt(obj.style.left); leftPos += direction; if (leftPos < 0) { direction = -direction; leftPos = 0; } else if (leftPos > 750) { direction = -direction; leftPos = 750; } obj.style.left = leftPos + 'px'; } function Move() { direction = 1;//can change the speed delay = 10; // can make it slow flagMoveInterval = window.setInterval('flagMove();',delay); } //--> </script> </head> <body onload="Move();"> <h1>The Flag of <a href="http://en.wikipedia.org/wiki/Honduras">HONDURAS</a> </h1> <div id="float" style="left:400px;"> <div class="c1"></div> <div class="c2"></div> <div class="c3"></div> <div class="c4"></div> </div> <div id = "button"><input type="button" value="Start!" onclick="Move()"/> <input type="button" value="Stop!" onclick="window.clearInterval(flagMoveInterval)"/></div> Similar TutorialsHi, I am not able to calculate the offsetwidth of the element which contains extra space in between the characters. for ex. if the element contains "A A" as a innerHTML value - if we calculate offsetwidth as 29 and also if the element contains "A A" value again I am getting the same offsetwidth as 29. While calculating the offsetwidth it is not calculating the empty space. May I know how to calculate the offsetwidth with the empty space because I need to insert the ellipsis (...) if it exceeds original width? Code snipet function fitStringToWidth(title,width,className) { var span = document.createElement("span"); span.className="titleBar-Title-1"; span.style.display='inline'; span.style.visibility = 'hidden'; span.style.padding = '0px'; document.body.appendChild(span); var result = title; span.innerHTML = result; alert("Offsetwidth : " + span.offsetWidth); .......................... } Thanks in advance. Arthik |