Div+css layout of the picture continuous scrolling JS implementation code _JAVASCRIPT skills

Source: Internet
Author: User
Tags setinterval
HTML Layout Code
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 {
/********* must be guaranteed beyond the width to be able to scroll *********/
width:600px;/* Visual Area Width * *
Overflow:hidden;
/********* must be guaranteed beyond the width to be able to scroll *********/
height:80px;
}
#demo1, #demo2 {
width:800px;/* whole picture Width * *
Float:left;
}
#demo img{
Display:block;
Float:left;
}
#demo Li {
Float:left;
width:60px;
height:80px;
}
-->
<!--
#demo0 {
/********* must be guaranteed beyond the width to be able to scroll *********/
width:600px;/* Visual Area Width * *
Overflow:hidden;
/********* must be guaranteed beyond the width to be able to scroll *********/
height:80px;
}
#demo11, #demo22 {
width:1020px;/* whole picture Width * *
Display:block;
height:80px;
}
#demo0 Li {
Float:left;
margin:0 5px;
width:60px;
height:80px;
}
-->
</style>
<body>
<!--structure must be--<div class= "Demo" >
<div class= "Demo1" ></div>
<div class= "Demo2" ></div>
</div>--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", "Onedemo");
ToRight ("Demo0", "demo11", "Demo22", "Ti2");
</script>
</body>

JS Core Code
Copy Code code as follows:

Call Scroll Left
ToLeft ("Demo", "Demo1", "Demo2", "Ti1")
Call Scroll Right
ToRight ("Demo0", "demo11", "Demo22", "Ti2")

function $ (ID)
{
return document.getElementById (ID)
}

Scroll the function to the left, the demo contains Demo1 and Demo2,speed is the scrolling speed, flag a page has more than one time set to a different arbitrary character.
function ToLeft (Demo,demo1,demo2,speed,flag)
{
demo=$ (demo);
demo1=$ (DEMO1);
demo2=$ (DEMO2)
Demo2.innerhtml=demo1.innerhtml
function Marquee ()
{
if (demo2.offsetwidth-demo.scrollleft<=0)
{
Demo.scrollleft-=demo1.offsetwidth
}
Else
{
demo.scrollleft++
}
}
Flag=setinterval (Marquee,speed)
Demo.onmouseover=function ()
{
Clearinterval (flag);
}
Demo.onmouseout=function ()
{
Flag=setinterval (Marquee,speed);
}
}


Scroll the function to the right, the demo contains Demo1 and Demo2,speed is the scrolling speed, flag a Web page has more than one time set to different arbitrary characters.
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);
}
}

If you need more features, you can refer to the following:
JavaScript four-direction picture scrolling effect
JavaScript Seamless scrolling up and down and fixed Gao Dingkuan pause effect (compatible with IE/FF)
Related Article

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.