• Jquery实现抖动效果


    参考文档: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时,自身抖动。

  • 相关阅读:
    iOS中过滤html文档中的标签
    十六进制函数转换UIColor对象
    vue使用echarts
    vue打包部署
    charels代理跨域访问接口
    vue 使用highcharts
    vue配置跨域
    命令行
    安装nvm
    vsCode个人设置
  • 原文地址:https://www.cnblogs.com/waw/p/8718394.html
Copyright © 2020-2023  润新知