jQuery 快速类切换器
尝试制作一个类切换器来执行以下操作下列的:
- 加载时 - 随机选择 10 个类之一添加到元素
- 悬停时 - 在 10 个类别之间快速(每 0.4 秒)切换
- 鼠标移出时 - 使当前类保持活动状态
我已经尝试了几种方法来执行此操作,但没有一种有效。
您认为做到这一点的最佳方法是什么?
Trying to make a class switcher that will do the following:
- On Load - randomly select one of 10 classes to add to an element
- While Hovering - Rapidly (every 0.4s) switch between 10 classes
- On mouseOut - leave the current class active
I've tried several ways of doing this, none of which have worked.
What do you think would be the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://jsfiddle.net/re73T/9/
http://jsfiddle.net/re73T/9/
这是在 jsFiddle 中工作的不同实现: http://jsfiddle.net/jfriend00/b7A4a/。这还确保随机生成的类名与前一个不同,因此颜色实际上每 400 毫秒更改一次,而不是跳过十分之一的更改,因为它生成与刚刚具有的颜色值相同的颜色值。
Here's a different implementation that works in your jsFiddle here: http://jsfiddle.net/jfriend00/b7A4a/. This one also makes sure that the randomly generated class name is different than the previous one so the color actually changes every 400ms rather than skipping a change 1 out of 10 times because it generates the same color value that it just had.