AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

jQuery通过扩展实现抖动效果的方法

51自学网 http://www.wanshiok.com
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;
}

2. 使用方法如下:
复制代码 代码如下:
$(function() {
  $('#btn').click(function() {
    $(this).shake(2,10,400);
  });
});

希望本文所述对大家的jQuery程序设计有所帮助。


jQuery,扩展,抖动效果,方法  
上一篇:javascript实现checkBox的全选,反选与赋值  下一篇:jQuery实现字符串按指定长度加入特定内容的方法