JavaScript implementation text Picture seamless scrolling effect code

Source: Internet
Author: User
Tags setinterval

Today to do the project encountered a scrolling effect, originally intended to do with marquee, because it is the HTML tag, write simple, but there is a problem is marquee can not achieve seamless scrolling, the Internet to find some methods, found that marquee can achieve seamless, But in the brain residue of IE environment.

No way, in order to achieve the requirements, oneself and from the Internet to find some relevant code to modify, and finally achieve the effect, now the code to share with you, there are questions to please more correct.

The code is as follows:

The code is as follows Copy Code

<! 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=utf-8 "/>
<title> text list seamlessly scroll up JavaScript code </title>
<style type= "Text/css" >
#xunhuan {
Overflow:hidden; /* The overflow part does not show * *
height:100px;
}
#xunhuan1, #xunhuan2 {height:auto;}
</style>
<body>
<div id= "Xunhuan" >
<div id= "Xunhuan1" >
<ul>
<li> This is the 1th article </li>
<li> This is the 2nd article </li>
<li> This is the 3rd article </li>
<li> This is the 4th article </li>
<li> This is the 5th article </li>
<li> This is the 6th article </li>
</ul>
</div>
<div id= "Xunhuan2" ></div>
</div>
<script>
var speed=10; The larger the number, the slower the speed.
var Tab=document.getelementbyid ("Xunhuan");
var Tab1=document.getelementbyid ("Xunhuan1");
var Tab2=document.getelementbyid ("Xunhuan2");
tab2.innerhtml=tab1.innerhtml; Clone Demo1 for Demo2
function Marquee () {
if (tab2.offsettop-tab.scrolltop<=0)//when scrolling to the junction of Demo1 and Demo2
Tab.scrolltop-=tab1.offsetheight//demo jump to the top
else{
tab.scrolltop++
}
}
var mymar=setinterval (marquee,speed);
Tab.onmouseover=function () {clearinterval (MyMar)};//to clear the timer when the mouse moves up to stop the scroll
Tab.onmouseout=function () {mymar=setinterval (marquee,speed)};//Reset timer when mouse is moved
</script>
</body>

It should be noted that in addition to the style I wrote in the styles, the other two points of attention is: the inside of Li can not float, the most peripheral xunhuan height is less than the height of the elements inside, to be enough for it to cycle rolling.

Example is the effect of scrolling up, if you want to scroll to the left, make the appropriate changes.

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.