mirror of https://github.com/layui/layui
优化 util 代码书写规范
parent
d1cb0dff94
commit
f900148416
|
@ -358,23 +358,23 @@ layui.define('jquery', function(exports){
|
||||||
// 让指定的元素保持在可视区域
|
// 让指定的元素保持在可视区域
|
||||||
toVisibleArea: function(options){
|
toVisibleArea: function(options){
|
||||||
options = $.extend({
|
options = $.extend({
|
||||||
margin: 160 //触发动作的边界值
|
margin: 160, // 触发动作的边界值
|
||||||
,duration: 200 //动画持续毫秒数
|
duration: 200, // 动画持续毫秒数
|
||||||
,type: 'y' //触发方向,x 水平、y 垂直
|
type: 'y' // 触发方向,x 水平、y 垂直
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
if(!options.scrollElem[0] || !options.thisElem[0]) return;
|
if(!options.scrollElem[0] || !options.thisElem[0]) return;
|
||||||
|
|
||||||
var scrollElem = options.scrollElem // 滚动元素
|
var scrollElem = options.scrollElem // 滚动元素
|
||||||
,thisElem = options.thisElem //目标元素
|
var thisElem = options.thisElem // 目标元素
|
||||||
,vertical = options.type === 'y' //是否垂直方向
|
var vertical = options.type === 'y' // 是否垂直方向
|
||||||
,SCROLL_NAME = vertical ? 'scrollTop' : 'scrollLeft' //滚动方法
|
var SCROLL_NAME = vertical ? 'scrollTop' : 'scrollLeft' // 滚动方法
|
||||||
,OFFSET_NAME = vertical ? 'top' : 'left' //坐标方式
|
var OFFSET_NAME = vertical ? 'top' : 'left' // 坐标方式
|
||||||
,scrollValue = scrollElem[SCROLL_NAME]() //当前滚动距离
|
var scrollValue = scrollElem[SCROLL_NAME]() // 当前滚动距离
|
||||||
,size = scrollElem[vertical ? 'height' : 'width']() //滚动元素的尺寸
|
var size = scrollElem[vertical ? 'height' : 'width']() // 滚动元素的尺寸
|
||||||
,scrollOffet = scrollElem.offset()[OFFSET_NAME] //滚动元素所处位置
|
var scrollOffet = scrollElem.offset()[OFFSET_NAME] // 滚动元素所处位置
|
||||||
,thisOffset = thisElem.offset()[OFFSET_NAME] - scrollOffet //目标元素当前的所在位置
|
var thisOffset = thisElem.offset()[OFFSET_NAME] - scrollOffet // 目标元素当前的所在位置
|
||||||
,obj = {};
|
var obj = {};
|
||||||
|
|
||||||
// 边界满足条件
|
// 边界满足条件
|
||||||
if(thisOffset > size - options.margin || thisOffset < options.margin){
|
if(thisOffset > size - options.margin || thisOffset < options.margin){
|
||||||
|
@ -397,8 +397,8 @@ layui.define('jquery', function(exports){
|
||||||
|
|
||||||
// 绑定委托事件
|
// 绑定委托事件
|
||||||
util.event.UTIL_EVENT_CALLBACK[attr] = function(){
|
util.event.UTIL_EVENT_CALLBACK[attr] = function(){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,key = othis.attr(attr);
|
var key = othis.attr(attr);
|
||||||
(typeof obj[key] === 'function') && obj[key].call(this, othis);
|
(typeof obj[key] === 'function') && obj[key].call(this, othis);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -411,11 +411,6 @@ layui.define('jquery', function(exports){
|
||||||
|
|
||||||
util.on = util.event;
|
util.on = util.event;
|
||||||
|
|
||||||
// DOM 尺寸变化,该创意来自:http://benalman.com/projects/jquery-resize-plugin/
|
|
||||||
/*
|
|
||||||
!function(a,b,c){"$:nomunge";function l(){f=b[g](function(){d.each(function(){var b=a(this),c=b.width(),d=b.height(),e=a.data(this,i);(c!==e.w||d!==e.h)&&b.trigger(h,[e.w=c,e.h=d])}),l()},e[j])}var f,d=a([]),e=a.resize=a.extend(a.resize,{}),g="setTimeout",h="resize",i=h+"-special-event",j="delay",k="throttleWindow";e[j]=250,e[k]=!0,a.event.special[h]={setup:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.add(b),a.data(this,i,{w:b.width(),h:b.height()}),1===d.length&&l()},teardown:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.not(b),b.removeData(i),d.length||clearTimeout(f)},add:function(b){function f(b,e,f){var g=a(this),h=a.data(this,i)||{};h.w=e!==c?e:g.width(),h.h=f!==c?f:g.height(),d.apply(this,arguments)}if(!e[k]&&this[g])return!1;var d;return a.isFunction(b)?(d=b,f):(d=b.handler,b.handler=f,void 0)}}}($,window);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 输出接口
|
// 输出接口
|
||||||
exports('util', util);
|
exports('util', util);
|
||||||
});
|
});
|
Loading…
Reference in New Issue