Reprint: Please specify the original link and the author's name ' Little Small '
Will the applet really replace everything? QQ Group: 139128168← Click Add Group
In small programs, lazy loading effect is a headache, because the small program is completely unable to manipulate the DOM, so the location of the operation in the small program, become extremely difficult ~ ~
See Special effects First:
We will split it into the following steps to explain ~ ~
1) How to get the position height of the picture
First look at a picture:
By knowing, the image position height can actually be calculated by Img.height + margin value.
JS Code:
Math.floor(i/2)*(img.height + margin-bottom);
Why Math.floor (I/2), because the same row two picture height, such as i=0 and I=1, through the Math.floor to the value of 0, so you can guarantee that the same row of two picture position height is the same value.
2) Replace the default picture
First look at the film:
Wxml Code:
<image src="{{arr[index] ? productArr[index].Image : ‘default.jpg‘}}"></image>
- The idea is obvious, the first Arr[index] is false, so the default is the defaults picture
- But as you move down, some arr[index] values become true, so replace the default picture
JS Code:
for (var0this.data.productArr.length; i++) { if (arrHight[i] < scrollTop) { iffalse) { true; } }}
The idea is quite clear, needless to say ~ ~
3) Lazy loading in fade effects
First look at the effect:
WXSS Code:
. Product_image{ opacity: 0; width: %; height: %; transition: opacity 1s linear 2s; }. Loaded{ opacity: 1;}
is actually a transition animation of opacity, so easy~~
SOURCE download
"Duang, not to forget the attention ~ ~"
It really blew up: the "Picture lazy loading" ultimate solution of the little program that makes people headache