“排队”非动画属性:attr
更新:好的,所以我看到我可以将每个 attr 替换包含在计时器的函数中。这意味着我会这样做五次;每个图形一次。但是,有没有更干净的方法来做到这一点?谢谢
,好的,所以我有五个不同的图像想要替换 src。但是,我希望每个都是连续的......替换第一个,然后替换第二个等等。
由于我正在更改属性源,动画队列将无济于事。
我尝试了简单的计时器插件并将其放入一个函数中,然后在每次 attr 替换后调用该函数,但所有 attr 都在函数调用之前发生。
然后,我将计时器函数、attr 替换以及对计时器函数的调用全部放在一个函数中,加载文档并调用该函数,但 attr 仍然一次性发生,然后函数调用。
所以,这是我在上面解释的最后一件事:
$(document).ready(function() {
function holdIt(){
myTimer = $.timer(2000,function(){
alert("yes");
});
};
function doMe() {
$('#visit').attr('src', 'images/visitGrow.jpg');
holdIt();
$('#real').attr('src', 'images/realGrow.jpg');
holdIt();
$('#life').attr('src', 'images/lifeGrow.jpg');
holdIt();
$('#retirement').attr('src', 'images/retirementGrow.jpg');
holdIt();
$('#center').attr('src', 'images/centerGrow.jpg');
};
doMe();
});
</script>
我知道我错过了一些东西,因为它必须很容易完成,但我还没有。有什么指点吗? PS...我正在使用简单的计时器插件。
另外,我应该注意,我只是在每次 attr 替换后寻找暂停,以便警报('yes');是的,我想我只会返回 false 或 null;或其他什么。
UPDATE: alright so I see that I can just include each attr replacement within the function of the timer. That means I do that five times; once for each graphic. But, is there a cleaner way to do this? Thanks
ok, so I have five different images I want to replace the src for. However, I want each one sequential.. replace the first, then the second etc.
Since I'm changing the attribute source, the animation que won't help.
I tried the simple timer plugin and put that in a function, then called the function after each attr replace but all attr's happen before the function calls.
Then, I put the timer function, the attr replacements with the calls to the timer function all inside a function, loaded the document and called that but still, attr happens all-at-once and then function calls.
So, here is the last thing I tried explained just above:
$(document).ready(function() {
function holdIt(){
myTimer = $.timer(2000,function(){
alert("yes");
});
};
function doMe() {
$('#visit').attr('src', 'images/visitGrow.jpg');
holdIt();
$('#real').attr('src', 'images/realGrow.jpg');
holdIt();
$('#life').attr('src', 'images/lifeGrow.jpg');
holdIt();
$('#retirement').attr('src', 'images/retirementGrow.jpg');
holdIt();
$('#center').attr('src', 'images/centerGrow.jpg');
};
doMe();
});
</script>
I know I'm missing something as it has to be easily accomplished but I don't have it yet. Any pointers? PS... I'm using simple plug-in for the timer.
Also, I should note that I'm just looking for a pause after each attr replace so where the alert('yes'); is, I thought I'd just return false or null; or whatever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
顺便说一句,自执行包装函数在这里创建一个本地范围,这样你就不会污染全局命名空间......
btw the self-executing wrapper function is here to create a local scope so that you don't polute the global namespace...
您可以使用一个简单的间隔,如下所示:
这利用了图像 URL 的约定,因此我们只是每 2 秒遍历一次数组,然后到达末尾,间隔就不会再次触发。
You could use a simple Interval, like this:
This takes advantage of your image URLs having a convention, so we're just stepping through the array every 2 seconds, then the end is reached the interval just doesn't fire again.