Use native JavaScript to implement banner scrolling transitions in Web pages

Source: Internet
Author: User

The code is as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>

<style type= "Text/css" >
*{
padding:0px;
margin:0px;
}

#banner {
width:100%;
Overflow:hidden;
White-space:nowrap;
}

#banner #inside {
width:9600px;
position:relative;
left:50%;
Margin-left: -960px;
Transition:all 1s ease;
}

#banner img{
width:1920px;
}


</style>

<script>
var num = 0;
Window.onload = function () {

var inside = document.getElementById ("Inside");

var interval = setinterval (function () {
inside.style.transition = "all 1s ease";
num++;
Switch (num) {
Case 1:
Inside.style.transition = "None";
Inside.style.marginLeft = ( -960) + "px";
Break
Case 2:
Inside.style.marginLeft = ( -960-1920) + "px";
Break
Case 3:
Inside.style.marginLeft = ( -960-1920*2) + "px";
Break
Case 4:
Inside.style.marginLeft = ( -960-1920*3) + "px";
num = 0;
Break
Default
Break
}
},2000);


}
</script>


<body>

<div id= "banner" >
<div id= "Inside" >
</div>

</div>

</body>

Use native JavaScript to implement banner scrolling transitions in Web pages

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.