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);} scriptShare
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!