jQuery CSS 关键帧
尝试使用 jQuery 制作一个简单的重复关键帧动画,
$(document).ready(function() {
$('body').mouseover(function() {
var animateloop = 0;
$(this).mouseout(function(){
animateloop++;
});
while (animateloop !== 1) {
$(this).delay(40).css(
'font-family':'Homestead'
).delay(40).css(
'font-family':'Arvo'
);
}
});
});
我认为上面的代码可以工作,但我不太了解 jQuery,所以我无法让它工作。
您可以在此处看到 JSFIDDLE:
Trying to make a simple repeated keyframed animation with jQuery
$(document).ready(function() {
$('body').mouseover(function() {
var animateloop = 0;
$(this).mouseout(function(){
animateloop++;
});
while (animateloop !== 1) {
$(this).delay(40).css(
'font-family':'Homestead'
).delay(40).css(
'font-family':'Arvo'
);
}
});
});
I thought this code above would work, but I don't understand jQuery all that much so I can't make it work.
You can see this a JSFIDDLE here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个错误:
冒号:
one error first:
the colon:
这有效。
问题是您的 .delay() 而不是您的 .css()
.delay() 用于属于队列一部分的项目,例如动画。
您可以使用 .queue() 或 setTimeout()
阅读此线程的更多信息:jQuery 延迟不起作用
类似于:
小提琴:http://jsfiddle.net/nPVxb/74/
This works.
The problem is your .delay() and not your .css()
.delay() is used for items that are part of a queue, like animations.
You can use .queue() or setTimeout()
Read more on this thread: jQuery delay not working
Something like :
Fiddle : http://jsfiddle.net/nPVxb/74/
假设您想要一个无限循环并且正在对象的范围内工作...
注意:
我使用一种老式方法在界面上强调私有函数。您不必以这种方式命名变量,而且它们不是私有的。
您会注意到我将“this”存储到“handle”中。您不能总是依赖于 this 的范围,例如从事件气泡调用对象函数、从公共接口调用它或在对象内部引用函数。所以我只是按照惯例这样做。
将此代码放入您的对象中,调用“start”函数,它应该继续执行其操作,直到您离开页面。另外,请确保清除递归超时,以免在页面刷新或页面导航时出现错误。
Assuming you want an infinite loop and are working within the scope of an object...
Notes:
I use an old school method of underscoring private functions on an interface. You don't have to name your variables that way, and they are not private.
You will notice that I store "this" into "handle". You can't always rely on the scope of this, such as calling an object function from an event bubble, calling it from a public interface, or referencing a function internally to the object. So I just do this as a convention.
Put this code into your object, call the 'start' function, and it should continue doing its thing until you leave the page. Also, make sure to clean up your recursive timeouts, less you get an error on page refresh or page navigation.