moveRight(num) problems!
moveRight(num) problems!
嘿,Stackoverflow!我对Javascript很陌生,但我很快就掌握了窍门。我正在做一个网站,但我不能完全让它工作。
首先我们有一个按钮。
<SPAN ID="button2">
<A HREF="#"
onClick="changeZIndex(1,'contactus');changeZIndex(0,'aboutus');changeZIndex(0,'pagethree');moveRight(310)">
<IMG NAME="two" SRC="contactus.gif"></A>
</SPAN>
接下来我们有控制moveRight 的代码块
<script type="text/javascript">
var userWidth = window.screen.width;
function moveRight(num) {
var pp2 = document.getElementById("bar");
var lft = parseInt(pp2.style.left);
var tim = setTimeout("moveRight()",10);
lft = lft+5;
pp2.style.left = lft+"px";
if (lft > num) {
pp2.style.left = num;
clearTimeout(tim);
}
}
</script>
动作很好。我遇到的问题是停止它,这就是这个片段的作用
pp2.style.left = lft+"px";
if (lft > num) {
pp2.style.left = num;
当(lft>num)和pp2.style.left=num中的num被一个实数(比如310)取代时,它就可以正常工作。但是,当"num"保留时,它不会停止。我之所以想用停止号来代替,是因为我有几个按钮,可以让酒吧在网站上的不同地方停止。我已经做了好几个小时了,我已经把我能想到的都做了。希望你们能比我做得更好!:)
这非常接近(除非对编码风格进行编辑)。在通过伪递归的后续条目中,"num"没有值。
<script type="text/javascript">
var userWidth = window.screen.width;
function moveRight(num)
{
var pp2 = document.getElementById("bar");
var lft = parseInt(pp2.style.left);
// you have give the next iteration of 'moveRight' the value for num.
var tim = setTimeout("moveRight("+ num +")",10);
lft = lft+5;
pp2.style.left = lft+"px";
if (lft > num)
{
// here, you have to make sure that you're adding the unit qualifier (px)
// to your style.
pp2.style.left = num + 'px';
clearTimeout(tim);
}
}
</script>
相关文章:
- JavaScript setInterval problems
- 如何使用 num.toString 和 str.split 查找整数的最后一位数字
- Problems with FB.api
- Problems with d3.scale.ordinal
- problems with EaselJS getCacheDataURL
- Num doenst在我的javascript中工作
- Javascript problems with Internet Explorer
- Problems IP-messagin and Twilio
- JavaScript DOM problems
- For Loops inside For Loops inside For Loops... = Problems
- http.get problems angular + nodejs
- jQuery Slider PHP/HTML Problems
- Problems with ng-include
- Problems with innerHTML
- JS Lint for Visual Studio 2010 problems
- 值==num 时的停止间隔
- 在 Javascript 中,num = +thenum ||错误的意思
- 将字符串 num 转换为数字 JavaScript
- Problems with JQuery .get() -
- moveRight(num) problems!