xfrontend/web/srczip/base/visibleChange.js

30 lines
712 B
JavaScript
Raw 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(){
// $('.table').visibleChange(function(isShow){
// if(isShow==1){
// //被看见了
// }else{
// //看不见了
// }
// });
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;
};
})();