This article for everyone to share the JavaScript image sliding effect implementation method, the specific contents are as follows, first look at the effect chart:
The mouse over the picture, show the complete which picture, remove is reset:
Simple CSS Plus JS operation DOM implementation:
Css:
#container {
height:477px;
margin:0 Auto;
border-right:1px solid #ccc;
border-bottom:1px solid #ccc;
Overflow:hidden;
position:relative;
}
#container img {
position:absolute;
Display:block;
left:0;
border-left:1px solid #ccc;
}
JS Operation:
Window.onload = function () {//container object var box = document.getElementById (' container ');
Get Picture NodeList object Set var IMGs = Box.getelementsbytagname (' img ');
The width of the single picture var imgwidth = imgs[0].offsetwidth;
Set Hidden door body exposed width var exposewidth = 180;
Set the total width of the container var boxwidth = ImgWidth + (imgs.length-1) * exposewidth;
Box.style.width = boxwidth + ' px '; Set the initial position of each door function Setimgspos () {for (var i = 1, len = Imgs.length i < len; i++) {imgs[i].style.left = IMGW
Idth + exposewidth * (i-1) + ' px ';
} setimgspos ();
Calculate the distance each door should be moved when it is opened var translate = Imgwidth-exposewidth; Bind event for each door for (var i = 0, len = imgs.length i < len; i++) {//Use the immediately called function table answer, in order to get a different I-value (function (i) {IMGS[I].O
Nmouseover = function () {//reset each door first setimgspos ();
Open the door for (var j = 1; J <= I; j +) {Imgs[j].style.left = parseint (Imgs[j].style.left, ten)-translate + ' px ';
Imgs[j].style.left = j*exposewidth + "px";
}
};
Imgs[i].onmouseout = function () { Setimgpos ();
};
}) (i);
}
};
Hopefully this article will help you learn about JavaScript programming.