This article mainly introduces the methods and principles for implementing blinds using native javascript. If you are interested, you can refer to the blinds! :
Principle:
The hollow lattice is like setting relative positioning attribute for each li, setting overflow: hidden, black block as li sub-element, height as twice of li, and setting absolute attribute, we just want to change its top value to get a change! (The excess block in the upper right corner is irrelevant to this figure)
Layout Analysis:
Note that top is worth changing! When top = 0 by default, the "first-floor top-up shop" is displayed. When top =-40px, the sub-elements of li are moved up to 40px, at this time, the displayed content is "first floor bottom shop". Note that the p element's package layer p
JS analysis:
1. enable multiple timers to achieve the effect.
2. Opposite execution direction
3. Execute multiple sets of motion
4. Accumulated Errors
5. animation generated at intervals
The JS Code is as follows:
Script window. onload = function () {var oUl = document. getElementById ('ul1'); var oUl2 = document. getElementById ('ul2'); toShow (oUl); // execute setTimeout (function () {toShow (oUl2) ;}, 4000) every four seconds; function toShow (obj) {var aDiv = obj. getElementsByTagName ('P'); var iNow = 0; var timer = null; var bBtn = true; setInterval (function () {toChange () ;}, 2000 ); function toChange () {timer = setInterval (function (){ If (iNow = aDiv. length) {clearInterval (timer); iNow = 0; bBtn =! BBtn;} else if (bBtn) {startMove (aDiv [iNow], {top: 0}, function () {var p = document. getElementsByClassName ('P-2'); for (var I = 0; I
0? Math. ceil (iSpeed): Math. floor (iSpeed); if (iCur! = Json [attr]) {bBtn = false;} obj. style [attr] = iCur + iSpeed + 'px ';} if (bBtn) {clearInterval (obj. timer); if (endFn) {endFn. call (obj) ;}}, 30) ;}// obtain the function getStyle (obj, attr) {if (obj. currentStyle) {return obj. currentStyle [attr];} else {return getComputedStyle (obj, false) [attr];} script
: Js implemented blinds
The above is all the content in this article, hoping to help you learn how to implement js blinds.