码迷,mamicode.com
首页 > Web开发 > 详细

Jquery实现抖动效果

时间:2015-08-05 21:54:04      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:

参考文档:jQuery 的扩展,实现抖动效果

背景:在项目中,登录页验证用户名和密码是否匹配,如果不匹配,则抖动输入框,提示用户输入错误。

将如下代码写到JS文件中:

 1 jQuery.fn.shake = function (intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
 2     this.each(function () {
 3         var jqNode = $(this);
 4         jqNode.css({ position: relative });
 5         for (var x = 1; x <= intShakes; x++) {
 6             jqNode.animate({ left: (intDistance * -1) }, (((intDuration / intShakes) / 4)))
 7             .animate({ left: intDistance }, ((intDuration / intShakes) / 2))
 8             .animate({ left: 0 }, (((intDuration / intShakes) / 4)));
 9         }
10     });
11     return this;
12 }

在View中引入以上JS文件以及Jquery文件,代码如下:

1 <script src="~/Scripts/jquery-1.8.2.js"></script>
2 <script src="~/Scripts/shakeYou.js"></script>
3 <script>
4     $(function () {
5         $(#btn1).click(function () {
6             $(this).shake(2, 10, 400);
7         });
8     });
9 </script>

以上代码的效果是:当点击btn时,自身抖动。

Jquery实现抖动效果

标签:

原文地址:http://www.cnblogs.com/SharpL/p/4705758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!