jQuery通过扩展实现抖动效果的方法
更新时间:2015年03月11日 16:41:37 作者:小编辑
这篇文章主要介绍了jQuery通过扩展实现抖动效果的方法,涉及jQuery扩展的技巧及抖动特效的实现方法,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了jQuery通过扩展实现抖动效果的方法。分享给大家供大家参考。具体实现方法如下:
1. JavaScript代码如下:
复制代码 代码如下:
jQuery.fn.shake = function(intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
this.each(function() {
var jqNode = $(this);
jqNode.css({position: ‘relative'});
for (var x=1; x<=intShakes; x++) {
jqNode.animate({ left: (intDistance * -1) },(((intDuration / intShakes) / 4)))
.animate({ left: intDistance },((intDuration/intShakes)/2))
.animate({ left: 0 },(((intDuration/intShakes)/4)));
}
});
return this;
}
this.each(function() {
var jqNode = $(this);
jqNode.css({position: ‘relative'});
for (var x=1; x<=intShakes; x++) {
jqNode.animate({ left: (intDistance * -1) },(((intDuration / intShakes) / 4)))
.animate({ left: intDistance },((intDuration/intShakes)/2))
.animate({ left: 0 },(((intDuration/intShakes)/4)));
}
});
return this;
}
2. 使用方法如下:
复制代码 代码如下:
$(function() {
$('#btn').click(function() {
$(this).shake(2,10,400);
});
});
$('#btn').click(function() {
$(this).shake(2,10,400);
});
});
希望本文所述对大家的jQuery程序设计有所帮助。
相关文章
使用CSS和jQuery模拟select并附提交后取得数据的代码
使用CSS和jQuery模拟select并实现提交后取得数据,详细实现及截图如下,感兴趣的朋友可以参考下2013-10-10
基于jQuery UI CSS Framework开发Widget的经验
jQuery UI CSS Framework是jQuery UI中的一个样式框架,可以利用jQuery Theme roller 来生成自己想要的css样式效果。我们可以利用jQuery UI的一些框架来开发出基于jQuery UI CSS Framework效果的插件来。2010-08-08


最新评论