xfrontend/web/srczip/base/visibleChange.js
2022-02-18 14:47:52 +08:00

33 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(){
X.pageLogic['visibleChange'] = {
init : function(parms){
var observer = new IntersectionObserver(function(changes){
changes.forEach(function(item,index){
var callback = $(item.target).data('_visibleChangeCall');
if(item.intersectionRatio > 0){
//target被观察的目标元素是一个 DOM 节点对象
callback && callback.call( item.target,1);
}else{
callback && callback.call( item.target,0);
}
});
});
$.fn.visibleChange = function(callback) {
this.each(function(){
$(this).data('_visibleChangeCall',callback);
observer.observe( this );
});
return this;
};
$('.layui-col').visibleChange(function(isShow){
if(isShow==1){
//被看见了
}else{
//看不见了
}
});
}
};
})();