作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,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>
Action 没问题。我遇到的问题是停止它,这就是这个代码片段的作用
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 - moveRight(num) 问题!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6092069/
嘿,Stackoverflow!我对 Javascript 还很陌生,但我很快就掌握了它的窍门。我正在开发一个网站,但无法完全正常运行。 首先我们有一个按钮。 接下来我们有控制 moveRig
我对这个简单的原型(prototype)设计有疑问: Game = function (moduleConfig, gameConfig) { this.moduleConfig = modu
我是一名优秀的程序员,十分优秀!