jQuery颜色样式交替
jQuery color style alternating
我正在尝试实现如下jQuery效果:http://jsfiddle.net/Qcghe/1/
$(document).ready(function() {
setInterval(function() {
$('small:nth-of-type(1)')
.animate( { color: '#F7B903' }, 750)
.animate( { color: '#FFF' }, 1000);
}, 1000);
setInterval(function() {
$('small:nth-of-type(2)')
.animate( { color: '#5BB6FD' }, 750)
.animate( { color: '#FFF' }, 1000);
}, 2000);
setInterval(function() {
$('small:nth-of-type(3)')
.animate( { color: '#D13360' }, 750)
.animate( { color: '#FFF' }, 1000);
}, 3000);
});
我想按以下顺序设置点的颜色动画:
- 白色,白色,白色(初始状态)
- 蓝色、白色、白色
- 蓝色、红色、白色
- 蓝色、红色、绿色
- 白色、红色、绿色
- 蓝色、白色、绿色
- 蓝色、红色、白色
- …然后回到初始状态
我在Photoshop中制作了一个动画GIF来帮助说明(黑白颠倒):
gif动画http://cdn.vpsunder10.com/1.gif
检查代码
$(document).ready(function() {
setInterval(function() {
$('small:nth-of-type(1)')
.animate( { color: '#F7B903' }, 1000)
.delay(4000)
.animate( { color: '#FFF' }, 1000);
$('small:nth-of-type(2)')
.delay(1000)
.animate( { color: '#5BB6FD' }, 1000)
.delay(5000)
.animate( { color: '#FFF' }, 1000);
$('small:nth-of-type(3)')
.delay(2000)
.animate( { color: '#D13360' }, 1000)
.delay(6000)
.animate( { color: '#FFF' }, 1000);
}, 10000);
});
http://jsfiddle.net/Qcghe/3/
因为它们每个都遵循一个相似但相关的动画循环,所以我会尝试将其表示为一个步骤序列,而不是三个单独的步骤。
var $dots = $('#dots span'),
colors = ['blue', 'red', 'green'], // Colour assigned to each dot, in order.
step = 1000; // Duration of each animation step in ms.
function cycle() {
$dots
.finish() // Ensure no animations still running from last cycle.
.each(function(index, dot) {
var $dot = $(dot),
color = colors[index];
$dot
.delay(index * step)
.animate({ color: color }, step)
.delay(step * 2)
.animate({ color: 'white' }, step)
.promise()
.done(function() {
// All but last should be restored to dot colour.
if (index != 2) $dot.animate({ color: color }, step);
})
;
});
// Set all the dots to white once animations have finished.
$dots.promise().done(function() { $dots.animate({ color: 'white' }, step) });
}
// Start immediately, and thereafter every seven steps.
cycle();
setInterval(cycle, step * 7);
jsFiddle演示
您可以通过使用step
变量使其更快或更慢。
(如果你感兴趣并且不必支持旧的浏览器,我也可以向你展示如何在带有关键帧动画的纯CSS中做到这一点。)
相关文章:
- javascript样式的背景颜色在设置时闪烁.ASP.NET
- Javascript时钟颜色样式
- jQuery颜色样式交替
- 如何从jquery中获取内联样式的边框颜色
- 如何设置'样式:color'淘汰赛中的颜色选择器.JS
- 如何更改chardin.js中的文本颜色和样式
- OL3:如何获取矢量图层的现有样式属性(例如填充颜色、描边颜色等)
- 如何将样式/颜色皮肤设为默认
- 使用Javascript为输入字段添加边框样式颜色(提交时没有值),该字段已经在css中带有!important标签的边
- 引导 NAV 方式在移动设备中折叠或展开时设置颜色样式
- 如何使样式元素的一部分成为函数?(IE:颜色:$random而不是颜色:红色)
- CSS3 颜色样式在使用 javascript 删除类后仍然存在
- 设置内容样式包含字体系列、字体大小和颜色的可编辑列表 (
- )
- JavaScript 函数来设置背景颜色的样式
- 如何使用内联背景颜色样式设置窗体输入字段的样式
- 如何在Xpage中动态更改样式???事实上,我想眨眼一个不同颜色的标签
- 我需要在点击页面中的链接时切换我的样式表,以便页面以不同的颜色主题显示
- 从字符串中删除所有ANSI颜色/样式
- 改变悬停样式颜色效果的函数
- 可以设置样式颜色大小吗