The method of realizing sliding door effect by JS _javascript skill

Source: Internet
Author: User

This paper illustrates the method of realizing sliding door effect by JS. Share to everyone for your reference, specific as follows:

Description: The mouse to move to a picture, will display the picture of the full picture, while the other pictures will show a general picture, the effect of the picture is as follows:

One, no animation effect of the movement

Ideas:

1. Set the initial position of each picture (the first one is fully displayed, and the 234 is partially exposed)
2. Calculate the moving distance of each door (that is, the uncovered part)
3. Binding Mouse over events

Window.onload=function () {var Box=document.getelementbyid ("box");
  var img=box.getelementsbytagname ("img");
  Single picture width var imgwidth=img[0].offsetwidth;
  Exposed width of Var exposewidth=160;
  Set the total width of the container var boxwidth=imgwidth+exposewidth* (img.length-1) box.style.width=boxwidth+ "px"; Set Picture initial position function Setimgspos () {for (Var i=1,len=img.length;i<len;i++) {//len is defined in the initialization statement for the loop so that you do not need to compute the IMG
    Number, than for (Var i=1;i 

Ii. the movement of acceleration and deceleration

Note: When you set the initial position of each door, you do not need to write a function, because the separate write to open and close the animation, will cause a cotton, twinkling twinkling.

Ideas:

1. Need the mouse to slide through the door's initial position
2. Need a mouse to slide through the end of this door position
3. Need a speed and timer to complete the slow moving process

Window.onload=function () {var Box=document.getelementbyid ("box");
  var img=box.getelementsbytagname ("img");
  Single picture width var imgwidth=img[0].offsetwidth;
  Exposed width of Var exposewidth=160;
  Set the total width of the container var boxwidth=imgwidth+exposewidth* (img.length-1) box.style.width=boxwidth+ "px"; Set picture initial position for (Var i=1,len=img.length;i<len;i++) {img[i].pos=img[i].style.left=imgwidth+exposewidth* (i-1) + "px"
  ;
    function Opendoor (el,translate) {var begin=parseint (el.pos);
    var end=begin-translate;
    var ispeed=10; settimeout (function () {el.style.left=parseint (el.style.left)-ispeed+ "px";//why not begin?  Each time the initial position will change ispeed*=1.5;
      There is no such sentence is uniform motion if (parseint (el.style.left) <=end) {el.style.left=end+ "px";
  }else{settimeout (arguments.callee,25);//timer has a name can be directly called, No Name, the original JS method Arguments.callee}},25);
  }; function Closedoor (el,translate) {var begin=parseint (el.pos)-translate;//Close the default is open var end=begin+translate;//Here You can write Var directlyEnd=parseint (El.pos);
    var ispeed=100; settimeout (function () {el.style.left=parseint (el.style.left) +ispeed+ "px";//why not begin? Each time the initial position will change Ispeed=math.ceil (ispeed*0.7);
      There is no such sentence is uniform motion if (parseint (el.style.left) >=end) {el.style.left=end+ "px";
  }else{settimeout (arguments.callee,25);//timer has a name can be directly called, No Name, the original JS method Arguments.callee}},25);
  };
  var translate=imgwidth-exposewidth; for (Var i=0,len=img.length;i<len;i++) {(function (i) {img[i].onmouseover=function () {) {//Open all loops to the left
        To for (Var j=1;j<=i;j++) {Opendoor (img[j],translate);
        //Close the whole loop to the right of itself (Var j=i+1;j 

More interested readers of JavaScript-related content can view this site: "JavaScript switching effects and tips summary", "JavaScript graphics Drawing Skills Summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

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.