HTML layout Code
Copy code The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<SCRIPT type = "text/JavaScript" src = "marquee. js"> </SCRIPT>
<Style type = "text/CSS">
<! --
*{
Margin: 0;
Padding: 0;
}
# Demo {
/********* Ensure that the image is rolled out of the specified width *********/
Width: 600px;/* visible area width */
Overflow: hidden;
/********* Ensure that the image is rolled out of the specified width *********/
Height: 80px;
}
# Demo1, # demo2 {
Width: 800px;/* width of the entire image */
Float: left;
}
# Demo IMG {
Display: block;
Float: left;
}
# Demo Li {
Float: left;
Width: 60px;
Height: 80px;
}
-->
<! --
# Demo0 {
/********* Ensure that the image is rolled out of the specified width *********/
Width: 600px;/* visible area width */
Overflow: hidden;
/********* Ensure that the image is rolled out of the specified width *********/
Height: 80px;
}
# Demo11, # demo22 {
Width: 1020px;/* width of the entire image */
Display: block;
Height: 80px;
}
# Demo0 Li {
Float: left;
Margin: 0 5px;
Width: 60px;
Height: 80px;
}
-->
</Style>
</Head>
<Body>
<! -- Required structure -- <Div class = "Demo">
<Div class = "demo1"> </div>
<Div class = "demo2"> </div>
</Div> -- the structure must be ---->
<Div id = "Demo">
<Ul id = "demo1">
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
</Ul>
<Ul id = "demo2"> </ul>
</Div>
<! -- <Div id = "demo0">
<Div id = "demo11">
<Ul>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
<Li> <a href = "#"> </a> </LI>
</Ul>
</Div>
<Div id = "demo22"> </div>
</Div> -->
<SCRIPT>
Toleft ("Demo", "demo1", "demo2", 30, "onedemo ");
// Toright ("demo0", "demo11", "demo22", 20, "ti2 ");
</SCRIPT>
</Body>
</Html>
JS core codeCopy codeThe Code is as follows: // call to scroll left
// Toleft ("Demo", "demo1", "demo2", 30, "ti1 ")
// Call to scroll to the right
// Toright ("demo0", "demo11", "demo22", 20, "ti2 ")
Function $ (ID)
{
Return document. getelementbyid (ID)
}
// scroll to the left. The demo contains demo1 and demo2. Speed indicates the scroll speed. If a flag contains multiple characters, it is set to any character.
function toleft (demo, demo1, demo2, speed, flag)
{< br> demo =$ (DEMO);
demo1 =$ (demo1 );
demo2 = $ (demo2)
demo2.innerhtml = demo1.innerhtml
function marquee ()
{< br> If (demo2.offsetwidth-demo. scrollleft <= 0)
{< br> demo. scrollleft-= demo1.offsetwidth
}< br> else
{< br> demo. scrollleft ++
}< BR >}< br> flag = setinterval (marquee, speed)
demo. onmouseover = function ()
{< br> clearinterval (FLAG);
}< br> demo. onmouseout = function ()
{< br> flag = setinterval (marquee, speed);
}< BR >}
// The scroll to the right function. The demo contains demo1 and demo2. Speed indicates the scroll speed. If a flag contains multiple characters, it is set to any character.
Function toright (demo, demo1, demo2, speed, flag)
{
Demo = $ (DEMO );
Demo1 = $(demo1 );
Demo2 = $ (demo2)
Demo2.innerhtml = demo1.innerhtml
Function marquee ()
{
If (Demo. scrollleft <= 0)
{
Demo. scrollleft = demo2.offsetwidth
}
Else
{
Demo. scrollleft --
}
}
Flag = setinterval (marquee, speed)
Demo. onmouseover = function ()
{
Clearinterval (FLAG );
}
Demo. onmouseout = function ()
{
Flag = setinterval (marquee, speed );
}
}
For more functions, refer to the following content:
Javascript image scrolling in four directions
Javascript seamless up, down, left, and right scrolling to add a fixed height, width, and pause effect (compatible with IE/ff)