/* * Extended JQ prototype: lazy, lazy loading, lazy animation *---Update the view state of the DOM in real time based on the window scrolling event to indicate whether the specified viewable area is in the defined visual region and make a change callback * $jq. ViewChange ({top:100,bottom:100 , Change:function (status) {}})---Status: ' in '/' out ' * $jq. ViewChange (' off ') * * $JQ [n].viewchange.status = ' "/' out '--- --The state ' in ' indicates that the DOM is in the specified visible area * */(function () {var $win = $ (window), var Winh = $win. Height (), var _isrun = true; $win. Resize (funct Ion () {Winh = $win. Height (), if (_isrun) {_isrun = False;settimeout (function () {$win. Trigger (' Scroll.viewchange '); _ Isrun = true;}, 100);}); var setStatus = function (params) {if (this.parentelement) {///determines if the DOM is still in the page var $self = $ (this); var offsetTop = $self. Offset (). TOP,SELFH = $self. Height (), scrolltop = $win. scrolltop (); if (scrolltop + Winh + params.bottom > OffsetTop && Scrolltop-params.top < OffsetTop + selfh) {if (This.viewChange.status!== ' in ') {this.viewChange.status = ' in ';p arams . Change.call (this, this.viewChange.status);}} else {if (this.viewChange.status!== ' out ') {this.viewChange.status = ' out ';p arams.cHange.call (this, this.viewChange.status);}}} else {$win. Off (' scroll. ' + This.viewChange.eventNamespace);}}; $.fn.viewchange = function (options) {if (options = = = ' off ') {This.each (function () {if (This.viewchange) {$win. Off (' Scroll. ' + this.viewChange.eventNamespace);d elete This.viewchange;}});} else {var params = {top:0,//increase or decrease the top range bottom:0,//increase or decrease the bottom range change: $.noop//Callback when the view state changes: function (status) {}};p Arams = $. Extend (params, options);p arams.top = parseint (params.top);p arams.bottom = parseint (Params.bottom); This.each ( function () {if (This.viewchange) {$win. Off (' scroll. ' + this.viewChange.eventNamespace);} This.viewchange = {eventnamespace: ' viewChange. ' + math.random (). toString (). Replace (' 0. ', '),}; $win. On (' scroll. ' + This.viewChange.eventNamespace, function () {Setstatus.call (this, params);}. Bind (this)); Setstatus.call (this, params);}); return this;};}) ();//Usage $jq.viewchange ({top:-100,//Zoom out Top range bottom:100,//Increase bottom range change:function (status) {if (status = = = ' in ') {// When scrolling to the specified visual area} else if(Status = = = ' Out ') {//When scrolling out the specified viewable area}}});
"Performance optimization" lazy, lazy loading, lazy animation---Update the DOM's view state in real-time based on the window scrolling event to indicate whether the specified visual area is in a defined and change callback