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实现unicode和字符的互相转换
Jul 18 Javascript
设置iframe的document.designMode后仅Firefox中其body.innerHTML为br
Feb 27 Javascript
.net,js捕捉文本框回车键事件的小例子(兼容多浏览器)
Mar 11 Javascript
js格式化时间和js格式化时间戳示例
Feb 10 Javascript
node.js使用cluster实现多进程
Mar 17 Javascript
JavaScript中对JSON对象的基本操作示例
May 21 Javascript
跨域请求的完美解决方法(JSONP, CORS)
Jun 12 Javascript
封装获取dom元素的简单实例
Jul 08 Javascript
JS类的定义与使用方法深入探索
Nov 26 Javascript
JavaScript html5 canvas实现图片上画超链接
Oct 20 Javascript
微信小程序自定义联系人弹窗
May 26 Javascript
微信小程序调用wx.getImageInfo遇到的坑解决
May 31 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中的M()与D()方法的区别
2013/06/22 PHP
file_get_contents(&quot;php://input&quot;, &quot;r&quot;)实例介绍
2013/07/01 PHP
Yii框架自定义数据库操作组件示例
2019/11/11 PHP
Laravel 框架基于自带的用户系统实现登录注册及错误处理功能分析
2020/04/14 PHP
jQuery 入门级学习笔记及源码
2010/01/22 Javascript
jQuery 设置 CSS 属性示例介绍
2014/01/16 Javascript
js制作简易年历完整实例
2015/01/28 Javascript
教你一步步用jQyery实现轮播器
2016/12/18 Javascript
深入理解Commonjs规范及Node模块实现
2017/05/17 Javascript
Ionic3 UI组件之Gallery Modal详解
2017/06/07 Javascript
JavaScript门面模式详解
2017/10/19 Javascript
详解webpack中的hash、chunkhash、contenthash区别
2018/01/05 Javascript
微信小程序slider组件使用详解
2018/01/31 Javascript
Vue组件中prop属性使用说明实例代码详解
2018/05/31 Javascript
jQuery实现炫丽的3d旋转星空效果
2018/07/04 jQuery
js监听html页面的上下滚动事件方法
2018/09/11 Javascript
小程序实现搜索框功能
2020/03/26 Javascript
通过angular CDK实现页面元素拖放的步骤详解
2020/07/01 Javascript
跟老齐学Python之Python文档
2014/10/10 Python
python字符串替换的2种方法
2014/11/30 Python
python计算文本文件行数的方法
2015/07/06 Python
Python编程求质数实例代码
2018/01/31 Python
python实现飞机大战
2018/09/11 Python
Python使用mongodb保存爬取豆瓣电影的数据过程解析
2019/08/14 Python
美国休闲服装品牌:Express
2016/09/24 全球购物
牛津在线药房:Oxford Online Pharmacy
2020/11/16 全球购物
饭店工作计划书
2014/01/10 职场文书
关于逃课的检讨书
2014/01/23 职场文书
公务员综合考察材料
2014/02/01 职场文书
结婚周年感言
2014/02/24 职场文书
劲霸男装广告词改编版
2014/03/21 职场文书
2014财务人员自我评价范文
2014/09/21 职场文书
巾帼文明岗事迹材料
2014/12/24 职场文书
初三英语教学计划
2015/01/23 职场文书
详解Redis基本命令与使用场景
2021/06/01 Redis
php去除数组中为0的元素的实例分析
2021/11/17 PHP