UNPKG

wx-wow

Version:

A CSS animation library is displayed when scrolling down the page.This project provides a convenient and easy-to-use animation implementation scheme for wechat Mini Program. By adding a simple animation class name and some simple parameters, the desired a

7 lines 2.73 kB
function setWatcher(a){observe(a,"data",function(c,b,f){var d=this;if("data.wxwow"==c)return 0;setTimeout(function(){ScrollFunc(d)},200)},!0,a,"data")} function observe(a,c,b,f,d,e){var g=a[c];f&&null!=g&&"object"===typeof g&&Object.keys(g).forEach(function(h){"__webviewId__"!=h&&"Object"!=h&&"$fv_wxWoWDataObserve"!=h&&"$fv_wxWoW"!=h&&observe(g,h,b,f,d,e+"."+h)});Object.defineProperty(a,c,{configurable:!0,enumerable:!0,set:function(h){b.call(d,e,h,g);g=h;f&&null!=g&&"object"===typeof g&&observe(a,c,b,f,d,e)},get:function(){return g}})} var ResetFunc=function(a,c){a.data.$fv_wxWoW.oldlist=[];a.setData({wxwow:{state:c,prefix:a.data.wxwow.prefix}})},ScrollFunc=function(a){wx.createSelectorQuery().selectAll(".wx-wow").boundingClientRect(".wx-wow").exec(function(c){"object"==typeof c[0]&&c[0].forEach(function(b){var f=b.dataset.wxWowId,d=b.dataset.wxWowOffset?parseInt(b.dataset.wxWowOffset/1500*a.data.$fv_wxwowHeight):0;a.data.$fv_wxwowHeight-d>b.top&&-1==a.data.$fv_wxWoW.oldlist.indexOf(f)&&(a.data.$fv_wxWoW.oldlist.push(f),a.data.$fv_wxWoW.maxIndex< f?a.data.$fv_wxWoW.maxIndex=f:"",a.data.wxwow={idx:".wowId-"+f,name:b.dataset.wxWowName?b.dataset.wxWowName:"",prefix:"animated",delayTime:b.dataset.wxWowDelay?b.dataset.wxWowDelay:"",durationTime:b.dataset.wxWowDuration?b.dataset.wxWowDuration:"",iteration:b.dataset.wxWowIteration?b.dataset.wxWowIteration:"",maxidx:a.data.$fv_wxWoW.maxIndex},a.setData({wxwow:a.data.wxwow}))})})},$FV_WXWOW={OnLoadFunc:function(a){var c=this;wx.getSystemInfo({success:function(b){c.setData({$fv_wxwowHeight:b.screenHeight, $fv_wxwowWidth:b.screenWidth,$fv_wxWoWDataObserve:null,$fv_wxWoWDataObserved:!1,$fv_wxWoW:{oldlist:[],maxIndex:0},wxwow:{}});setWatcher(c)}})},OnHideFunc:function(a){this.data.wxwowConfig&&!this.data.wxwowConfig.repeat?ResetFunc(this,"RESET-REPEAT"):ResetFunc(this,"RESET")},OnShowFunc:function(a){var c=this;c.data.wxwowConfig&&!c.data.wxwowConfig.repeat?"":setTimeout(function(){ScrollFunc(c)},200)},OnPageScrollFunc:function(a){ScrollFunc(this)}},$fv_wowPage=Page; module.exports=function(a){var c=a.onPageScroll,b=a.onShow,f=a.onHide;a.onLoad=function(d){return function(e){"function"==typeof $FV_WXWOW.OnLoadFunc&&$FV_WXWOW.OnLoadFunc.call(this,e);d&&d.call(this,e)}}(a.onLoad);a.onShow=function(d){return function(e){"function"==typeof $FV_WXWOW.OnShowFunc&&$FV_WXWOW.OnShowFunc.call(this,e);d&&d.call(this,e)}}(b);a.onHide=function(d){return function(e){"function"==typeof $FV_WXWOW.OnHideFunc&&$FV_WXWOW.OnHideFunc.call(this,e);d&&d.call(this,e)}}(f);a.onPageScroll= function(d){return function(e){"function"==typeof $FV_WXWOW.OnPageScrollFunc&&$FV_WXWOW.OnPageScrollFunc.call(this,e.scrollTop);d&&d.call(this,e)}}(c);return $fv_wowPage.call(this,a)};