layer扩展打开/关闭动画的方法


Posted in Javascript onSeptember 23, 2019

1. 打开窗口时,支持自定义或者第三方动画

打开layer.js,定位到函数:Class.pt.creat ,

找到代码:

//为兼容jQuery3.0的css动画影响元素尺寸计算
    if (doms.anim[config.anim]) {
      var animClass = 'layer-anim ' + doms.anim[config.anim];
      that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $(this).removeClass(animClass);
      });
    }

修改为(此处只是针对css动画库animate):

//为兼容jQuery3.0的css动画影响元素尺寸计算
    if (doms.anim[config.anim]) {
      var animClass = 'layer-anim ' + doms.anim[config.anim];
      that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $(this).removeClass(animClass);
      });
    } else {
      //支持自定义的,或者第三方弹出动画
      var animClass = config.anim;
      var animated = 'animated';
      that.layero.addClass(animated);
      that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $(this).removeClass(animClass);
        $(this).removeClass(animated);
      });
    }

至此,layer便可支持其他弹出动画。

2.关闭窗口时,支持自定义或者第三方动画(layer.open时需传入新增参数:closeAnim)

打开layer.js

定位到函数:Class.pt.config

新增参数:

closeAnim: 'layer-anim-close',

定位到函数:Class.pt.creat

找到代码:

//记录关闭动画
    if (config.isOutAnim) {
      that.layero.data('isOutAnim', true);
    }

修改为:

//记录关闭动画
    if (config.isOutAnim) {
      that.layero.data('isOutAnim', true);
      that.layero.data('closeAnim', config.closeAnim);
    }

定位函数到:layer.close

找到代码:

if (layero.data('isOutAnim')) {
      layero.addClass('layer-anim ' + closeAnim);
    }
 
    $('#layui-layer-moves, #layui-layer-shade' + index).remove();
    layer.ie == 6 && ready.reselect();
    ready.rescollbar(index);
    if (layero.attr('minLeft')) {
      ready.minIndex--;
      ready.minLeft.push(layero.attr('minLeft'));
    }
 
    if ((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')) {
      remove()
    } else {
      setTimeout(function () {
        remove();
      }, 200);
    }

修改为:

if (layero.data('isOutAnim')) {
      if (layero.data("closeAnim") === closeAnim) {
        layero.addClass('layer-anim ' + closeAnim);
      } else {
        layero.addClass(layero.data("closeAnim") + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
          $('#layui-layer-moves, #layui-layer-shade' + index).remove();
          remove();
        });
      }
    }
    if (layero.data("closeAnim") === closeAnim) {
      $('#layui-layer-moves, #layui-layer-shade' + index).remove();
      layer.ie == 6 && ready.reselect();
      ready.rescollbar(index);
      if (layero.attr('minLeft')) {
        ready.minIndex--;
        ready.minLeft.push(layero.attr('minLeft'));
      }
 
      if ((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')) {
        remove()
      } else {
        setTimeout(function () {
          remove();
        }, 200);
      }
    }

好啦,关闭也可以支持第三方动画啦。

以上这篇layer扩展打开/关闭动画的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript编程起步(第五课)
Jan 10 Javascript
web 页面分页打印的实现
Jun 22 Javascript
jQuery Validation插件remote验证方式的Bug解决
Jul 01 Javascript
javascript操作css属性
Dec 30 Javascript
ECMAScript5中的对象存取器属性:getter和setter介绍
Dec 08 Javascript
javaScript基础语法介绍
Feb 28 Javascript
探讨JavaScript中的Rest参数和参数默认值
Jul 29 Javascript
js中数组结合字符串实现查找(屏蔽广告判断url等)
Mar 30 Javascript
微信小程序 配置文件详细介绍
Dec 14 Javascript
简单实现js进度条加载效果
Mar 25 Javascript
vue学习教程之带你一步步详细解析vue-cli
Dec 26 Javascript
JavaScript 链表定义与使用方法示例
Apr 28 Javascript
layui字体图标 loading图标静止不旋转的解决方法
Sep 23 #Javascript
解决layer.confirm快速点击会重复触发事件的问题
Sep 23 #Javascript
小程序最新获取用户昵称和头像的方法总结
Sep 23 #Javascript
中级前端工程师必须要掌握的27个JavaScript 技巧(干货总结)
Sep 23 #Javascript
layui内置模块layim发送图片添加加载动画的方法
Sep 23 #Javascript
微信头像地址失效踩坑记附带解决方案
Sep 23 #Javascript
微信小程序如何获取用户头像和昵称
Sep 23 #Javascript
You might like
ThinkPHP之N方法实例详解
2014/06/20 PHP
ThinkPHP模板中判断volist循环的最后一条记录的验证方法
2014/07/01 PHP
PHP中的类型约束介绍
2015/05/11 PHP
基于PHPexecl类生成复杂的报表表头示例
2016/10/14 PHP
javascript 鼠标悬浮图片显示原图 移出鼠标后原图消失(多图)
2009/12/28 Javascript
JavaScript 布尔操作符解析  &amp;&amp; || !
2012/08/10 Javascript
jQuery阻止事件冒泡具体实现
2013/10/11 Javascript
jQuery提交多个表单的小技巧
2014/07/27 Javascript
jQuery语法小结(超实用)
2015/12/31 Javascript
bootstrap table操作技巧分享
2017/02/15 Javascript
详谈js原型继承的一些问题
2017/09/06 Javascript
详解jQuery中的isPlainObject()使用方法
2018/02/27 jQuery
js正则相关知识点专题
2018/05/10 Javascript
vue 中的 render 函数作用详解
2020/02/28 Javascript
vue项目使用$router.go(-1)返回时刷新原来的界面操作
2020/07/26 Javascript
使用Python的Zato发送AMQP消息的教程
2015/04/16 Python
详解Python中映射类型的内建函数和工厂函数
2015/08/19 Python
Python中Collections模块的Counter容器类使用教程
2016/05/31 Python
Python中的数学运算操作符使用进阶
2016/06/20 Python
Python Sqlite3以字典形式返回查询结果的实现方法
2016/10/03 Python
python如何使用正则表达式的前向、后向搜索及前向搜索否定模式详解
2017/11/08 Python
python logging日志模块原理及操作解析
2019/10/12 Python
OpenCV Python实现图像指定区域裁剪
2021/03/12 Python
鼠标滚轮事件和Mac触控板双指事件
2019/12/23 HTML / CSS
艺术专业大学生自我评价
2013/09/22 职场文书
计算机专业毕业生推荐信
2013/11/25 职场文书
门卫班长岗位职责
2013/12/15 职场文书
50岁生日感言
2014/01/23 职场文书
关于建议书的格式范文
2014/05/20 职场文书
意外死亡赔偿协议书
2014/10/14 职场文书
四风问题专项整治工作情况报告
2014/10/28 职场文书
教师党的群众路线教育实践活动个人整改措施
2014/11/04 职场文书
子女赡养老人协议书
2016/03/23 职场文书
基于Redis位图实现用户签到功能
2021/05/08 Redis
分布式架构Redis中有哪些数据结构及底层实现原理
2022/03/13 Redis
JavaScript原型链中函数和对象的理解
2022/06/16 Javascript