This time I will bring you the principle and implementation of jquery's lazy loading. What are the things to note when implementing jquery's lazy loading? The following is a practical case, let's take a look.
The principle of lazy loading1. Code implementation, load into the current viewport:function isVisible($node){ var winH = $(window).height(), scrollTop = $(window).scrollTop(), offSetTop = $(window).offSet().top; if (offSetTop < winH + scrollTop) { return true; } else { return false; } }
eventlistening Function, let the browser check whether the element appears within the visible range of the window every time it scrolls:
$(window).on("scroll", function{ if (isVisible($node)){ console.log(true); } })
var hasShowed = false; $(window).on("sroll",function{ if (hasShowed) { return; } else { if (isVisible($node)) { hasShowed = !hasShowed; console.log(true); //ajax请求刷新view层 } } })
Other related articles!
Related reading:Problems with VUE-CLI @2.9.1 and later versions
How to customize user settings for WebStorm
The above is the detailed content of The principle and implementation of jquery's lazy loading. For more information, please follow other related articles on the PHP Chinese website!