Example code of infinite loop scrolling of Javascript images

Source: Internet
Author: User
Tip: you can modify some code before running

<!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" xml:lang="en" lang="en"><head> <title></title> <style type="text/css">* {Padding: 0; margin: 0;} body {text-align: center ;} # photo-list {/* calculate the width of the three images (including width, padding, border, and whitelist between images: 3*(100 + 2*2 + 1*2 + 9)-9 the reason why 9 is subtracted is that the right side of the third image is White */width: 336px; /* Image width (including height, padding, and border): 100 + 2*2 + 1*2 */height: Pixel px; margin: 50px auto; overflow: hidden; border: 1px dashed # ccc ;}# photo-list ul {list-style: none ;}# photo-list li {float: left; padding-right: 9px ;} # photo-list img {border: 1px solid # ddd; background: # fff; padding: 2px ;}</style></head><body><div id="photo-list"> <ul id="scroll"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul></div><script type="text/javascript">Var id = function (el) {return document. getElementById (el) ;}, c = id ('photo-list'); if (c) {varul = id ('scroll '), lis = ul. getElementsByTagName ('Lil'), itemCount = lis. length, width = lis [0]. offsetWidth, // Get the width of each img container marquee = function () {c. scrollLeft + = 2; if (c. scrollLeft % width <= 1) {// When c. when scrollLeft and width are equal, append the first img to the last ul. appendChild (ul. getElementsByTagName ('Lil') [0]); c. scrollLeft = 0 ;}}, speed = 50; // The greater the value, the slower the ul. style. width = width * itemCount + 'px '; // after loading, set the container length var timer = setInterval (marquee, speed); c. onmouseover = function () {clearInterval (timer) ;}; c. onmouseout = function () {timer = setInterval (marquee, speed );};};</script></body></html></td> </tr></table>
Tip: you can modify some code before running

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.