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 相关文章推荐
window.ActiveXObject使用说明
Nov 08 Javascript
javascript中IE浏览器不支持NEW DATE()带参数的解决方法
Mar 01 Javascript
JS中判断null、undefined与NaN的方法
Mar 26 Javascript
搭建pomelo 开发环境
Jun 24 Javascript
探讨js字符串数组拼接的性能问题
Oct 11 Javascript
jQuery选择器源码解读(四):tokenize方法的Expr.preFilter
Mar 31 Javascript
简介JavaScript中setUTCSeconds()方法的使用
Jun 12 Javascript
AngularJS  $modal弹出框实例代码
Aug 24 Javascript
js实现图片粘贴上传到服务器并展示的实例
Nov 08 Javascript
layui表格 列自动适应大小失效的解决方法
Sep 06 Javascript
详解ES6 扩展运算符的使用与注意事项
Nov 12 Javascript
手动实现vue2.0的双向数据绑定原理详解
Feb 06 Vue.js
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
逆序二维数组插入一元素的php代码
2012/06/08 PHP
如何使用PHP批量去除文件UTF8 BOM信息
2013/08/05 PHP
CodeIgniter配置之SESSION用法实例分析
2016/01/19 PHP
浅谈PHP中其他类型转化为Bool类型
2016/03/28 PHP
javascript preload&amp;lazy load
2010/05/13 Javascript
JavaScript单元测试ABC
2012/04/12 Javascript
Javascript alert消息换行的方法
2013/08/07 Javascript
使用js解决由border属性引起的div宽度问题
2013/11/26 Javascript
js实现全国省份城市级联下拉菜单效果代码
2015/09/07 Javascript
Jquery1.9.1源码分析系列(十五)动画处理之外篇
2015/12/04 Javascript
基于jQuery实现数字滚动效果
2017/01/16 Javascript
js记录点击某个按钮的次数-刷新次数为初始状态的实例
2017/02/15 Javascript
angular4实现tab栏切换的方法示例
2017/10/21 Javascript
JS实现移动端整屏滑动的实例代码
2017/11/10 Javascript
Bootstrap treeview实现动态加载数据并添加快捷搜索功能
2018/01/07 Javascript
JSONP原理及应用实例详解
2018/09/13 Javascript
React和Vue中监听变量变化的方法
2018/11/14 Javascript
vue父组件给子组件的组件传值provide inject的方法
2019/10/23 Javascript
Vue中函数防抖节流的理解及应用实现
2020/04/24 Javascript
深入了解Vue3模板编译原理
2020/11/19 Vue.js
Python的Django应用程序解决AJAX跨域访问问题的方法
2016/05/31 Python
pytorch 实现打印模型的参数值
2019/12/30 Python
scrapy与selenium结合爬取数据(爬取动态网站)的示例代码
2020/09/28 Python
Melissa香港官网:MDreams
2016/07/01 全球购物
英国美术用品购物网站:Cass Art
2019/10/08 全球购物
广州某公司软件工程师面试题
2014/12/22 面试题
应届生会计电算化求职信
2013/10/03 职场文书
告诉你怎样写创业计划书
2014/01/27 职场文书
预防煤气中毒方案
2014/06/16 职场文书
民主评议党员登记表自我评价
2014/10/20 职场文书
结婚主持人致辞
2015/07/28 职场文书
CAD实训总结范文
2015/08/03 职场文书
小学语文课《掌声》教学反思
2016/03/03 职场文书
关于保护环境的建议书
2019/06/24 职场文书
教你使用vscode 搭建react-native开发环境
2021/07/07 Javascript
Java版 单机五子棋
2022/05/04 Java/Android