Friends who have used QQ space should be familiar with this. The results are amazing, but they are implemented using flash. Can javascript be used? I have been pondering for three days, I finally finished it, but it is still not perfect in some places. I hope you will understand it more. I will make it perfect in the future.
Let's start with the following ideas::
First, dynamically create an html Structure
Copy codeThe Code is as follows:
<Div style = "overflow-x: hidden;">
<Table border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Td> ......... .... </td>
<Td> </td>
</Tr>
</Table>
</Div>
This is critical, and then set a timer to simulate the movement of img, and bind the onmouseenter and onmouseleave events of the outer div. Finally, return the outer div object.
See the code below
Copy codeThe Code is as follows:
Sx. activex. dynamicpic = {
Init: function (imga, border, margin, w, h, step, speed ){
Var demo = document. createElement ("div ");
Var tbody = document. createElement ("tbody ");
Var demo1 = document. createElement ("td ");
Var demo2 = document. createElement ("td ");
Var table = document. createElement ("<table border =/" 0/"cellspacing =/" 0/"cellpadding =/" 0/"> ");
Var tr = document. createElement ("tr ");
Demo. style. position = "absolute ";
Demo. style. height = h + "px ";
Demo. style. width = w + "px ";
Demo. style. overflowX = "hidden ";
For (var I = 0; I Var img = document. createElement ("img ")
Img. src = imga [I];
Img. style. height = h + "px ";
Img. style. width = parseInt (w/imga. length) + "px ";
Demo1.appendChild (img)
}
Tr. appendChild (demo1 );
Tr. appendChild (demo2 );
Tbody. appendChild (tr );
Table. appendChild (tbody );
Demo. appendChild (table );
Var c = demo1.all;
For (var I = 0; I <c. length; I ++ ){
C [I]. style. marginLeft = margin + "px ";
C [I]. style. border = border;
}
Demo2.innerHTML = demo1.innerHTML
Function Marquee (){
If (demo2.offsetWidth-demo. scrollLeft <= 0 ){
// Alert (demo. scrollLeft );
Demo. scrollLeft-= demo1.offsetWidth ;}
Else {
Demo. scrollLeft + = step;
}
}
Var MyMar = setInterval (Marquee, speed );
Demo. onmouseenter = function (){
ClearInterval (MyMar );
Var t = document. elementFromPoint (window. event. clientX, window. event. clientY );
If (t. tagName! = "IMG ")
Return;
If (t. offsetHeight> demo. offsetHeight + 10)
Return;
// Alert (t. src );
Var d = document. createElement ("img ");
D. style. height = t. offsetHeight + 50 + "px ";
D. style. width = t. offsetWidth + 50 + "px ";
D. style. position = "absolute ";
D. style. top = "-25px ";
If (t. parentNode = demo2 ){
D. style. left = t. offsetLeft + demo1.offsetWidth-20 + "px ";
// Alert (1 );
// Demo. scrollLeft-= demo1.offsetWidth;
} Else {
D. style. left = t. offsetLeft-25 + "px ";}
// Alert (d. style. left );
// Alert (window. event. clientX );
// Alert (t. offsetLeft-demo.scrollLeft + demo. offsetWidth-25 );
D. src = t. src;
D. onmouseleave = function (){
D. parentNode. removeChild (d );
MyMar = setInterval (Marquee, speed)
}
// Alert (1 );
// Demo. style. overflow = "visible ";
Demo1.appendChild (d );
// Alert (m. innerHTML );
}
Demo. onmouseleave = function () {MyMar = setInterval (Marquee, speed )}
Return demo;
}
}
The imga of the function parameter is the array of the img address you want to input, border is the border attribute of the image, margin is the distance between images, w is the width of the outer div, h is the same, step is the number of steps for the timer to move an image, and speed is the timer interval.
The timer code above borrowed some code from the Internet, but I made some improvements myself.
The call code is as follows:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> Untitled Document </title>
</Head>
<Body>
<Script src = "kongjian. js"> </script>
<Script>
Var a = sx. activex. dynamicpic. init (["1 (1).jpg", "1.jpg"," 1 (22.16.jpg "," 1 (32.16.jpg "]," 2px red solid ", 5,500,100 );
Document. body. appendChild ();
</Script>
</Body>
</Html>
Okay, basically. Please have more information if you have any questions!