


js control multiple images left and right scroll switching effect code sharing_javascript skills
The example in this article describes the effect of js controlling the left and right scrolling switching of multiple images. Share it with everyone for your reference. The details are as follows:
This is a pure js tool that realizes automatic left and right smooth scrolling of images by clicking the left and right buttons. The default is left and right scrolling in groups of 5. You can manually modify the js parameters to change the number of slides.
Operation rendering: -------------------View effect-------------------
Tips: If the browser does not work properly, you can try switching the browsing mode.
The js code shared with you to control the left and right scrolling switching effect of multiple images is as follows
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js控制多图左右滚动切换效果</title> <link href="css/jiaobenzhijia.css" type="text/css" rel="stylesheet" /> <script type="text/javascript"> window.onload = function () { var oBtnLeft = document.getElementById("goleft"); var oBtnRight = document.getElementById("goright"); var oDiv = document.getElementById("indexmaindiv"); var oDiv1 = document.getElementById("maindiv1"); var oUl = oDiv.getElementsByTagName("ul")[0]; var aLi = oUl.getElementsByTagName("li"); var now = -5 * (aLi[0].offsetWidth + 13); oUl.style.width = aLi.length * (aLi[0].offsetWidth + 13) + 'px'; oBtnRight.onclick = function () { var n = Math.floor((aLi.length * (aLi[0].offsetWidth + 13) + oUl.offsetLeft) / aLi[0].offsetWidth); if (n <= 5) { move(oUl, 'left', 0); } else { move(oUl, 'left', oUl.offsetLeft + now); } } oBtnLeft.onclick = function () { var now1 = -Math.floor((aLi.length / 5)) * 5 * (aLi[0].offsetWidth + 13); if (oUl.offsetLeft >= 0) { move(oUl, 'left', now1); } else { move(oUl, 'left', oUl.offsetLeft - now); } } var timer = setInterval(oBtnRight.onclick, 5000); oDiv.onmouseover = function () { clearInterval(timer); } oDiv.onmouseout = function () { timer = setInterval(oBtnRight.onclick, 5000); } }; function getStyle(obj, name) { if (obj.currentStyle) { return obj.currentStyle[name]; } else { return getComputedStyle(obj, false)[name]; } } function move(obj, attr, iTarget) { clearInterval(obj.timer) obj.timer = setInterval(function () { var cur = 0; if (attr == 'opacity') { cur = Math.round(parseFloat(getStyle(obj, attr)) * 100); } else { cur = parseInt(getStyle(obj, attr)); } var speed = (iTarget - cur) / 6; speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); if (iTarget == cur) { clearInterval(obj.timer); } else if (attr == 'opacity') { obj.style.filter = 'alpha(opacity:' + (cur + speed) + ')'; obj.style.opacity = (cur + speed) / 100; } else { obj.style[attr] = cur + speed + 'px'; } }, 30); } </script> </head> <body style="background:#CCC;"> <div class="indexmaindiv" id="indexmaindiv"> <div class="indexmaindiv1 clearfix" > <div class="stylesgoleft" id="goleft"></div> <div class="maindiv1 " id="maindiv1"> <ul id="count1"> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/1.jpg" /></div> <div class="teanames">乐静老师1</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/2.jpg" /></div> <div class="teanames">乐静老师2</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/3.jpg" /></div> <div class="teanames">乐静老师3</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/4.jpg" /></div> <div class="teanames">乐静老师4</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/5.jpg" /></div> <div class="teanames">乐静老师5</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/6.jpg" /></div> <div class="teanames">乐静老师6</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/7.jpg" /></div> <div class="teanames">乐静老师7</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/8.jpg" /></div> <div class="teanames">乐静老师8</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/1.jpg" /></div> <div class="teanames">乐静老师9</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/2.jpg" /></div> <div class="teanames">乐静老师10</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/3.jpg" /></div> <div class="teanames">乐静老师11</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/4.jpg" /></div> <div class="teanames">乐静老师12</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/5.jpg" /></div> <div class="teanames">乐静老师13</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/6.jpg" /></div> <div class="teanames">乐静老师14</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> <li> <div class="playerdetail"> <div class="detailimg"><img src="images/7.jpg" /></div> <div class="teanames">乐静老师15</div> <div class="teadetail">获得新加坡南阳理工学院计算机学士学位擅长营销学培训</div> <a class="checkdetail" href="http://www.jb51.net"></a> </div> </li> </ul> </div> <div class="stylesgoright" id="goright"></div> </div> </div> </body> </html>
The above is the js code to control the left and right scrolling switching effect of multiple images shared with you. I hope you will like it.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
