Introduction to implementation of blinds by native js _ javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.