Implement seamless scrolling in JavaScript and share the code to the sidebar instance _ javascript skills

Source: Internet
Author: User
This article provides seamless scrolling and sidebar effects through js Code, which are often encountered in projects. The following small series will organize the code and share it with the script home platform for your reference, the Code has been directly pasted to everyone, and the code solves a problem!

The following code describes the js seamless rolling instance code:

The Code is as follows:

 Untitled documentScript window. onload = function () {var oDiv = document. getElementById ('p1'); var oUl = oDiv. getElementsByTagName ('ul ') [0]; var aLi = oUl. getElementsByTagName ('lil'); var speed = 3oUl. innerHTML = oUl. innerHTML + oUl. innerHTML; oUl. style. width = aLi [0]. offsetWidth * aLi. length + 'px '; function move () {if (oUl. offsetLeft <-oUl. offsetWidth/2) {oUl. style. left = '0';} if (oUl. offsetLeft> 0) {oUl. style. left =-oUl. offsetWidth/2 + 'px ';} oUl. style. left = oUl. offsetLeft + speed + 'px ';}; var timer = setInterval (move, 30); oDiv. onmouseover = function () {clearInterval (timer) ;}; oDiv. onmouseout = function () {timer = setInterval (move, 30);} document. getElementsByTagName ('A') [0]. onclick = function () {speed =-3;}; document. getElementsByTagName ('A') [1]. onclick = function () {speed = 3 ;};}; scriptLeft to right

The js Code shared to the sidebar is as follows:

The Code is as follows:

 Untitled documentScript window. onload = function () {var oDiv = document. getElementById ('p1'); oDiv. onmouseover = function () {startMove (10, 0);} oDiv. onmouseout = function () {startMove (-10,-100) ;}} var timer = null; function startMove (speed, locall) {var oDiv = document. getElementById ('p1'); clearInterval (timer); timer = setInterval (function () {if (oDiv. offsetLeft = locall) {clearInterval (timer);} else {oDiv. style. left = oDiv. offsetLeft + speed + 'px ';}, 30);} script

Share

The above section describes how to implement seamless scrolling in JavaScript and share the instance code in the sidebar. The code is easy to understand. If you have any questions, please leave a message!

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.