Example tutorial of seamless scrolling of js carousel chart
This article mainly introduces the seamless scrolling effect of js carousel chart in detail, which has a certain reference value. Interested friends can refer to it
How to start and end the carousel chart when making it If they cannot be connected, the effect will be a bit ugly. Here is a method I commonly use:
Let me explain in words first:
If you want to display 5 pictures, they are 1, 2, and 3. ,4,5 So the introduction of the code is like this: 1,2,3,4,5,1
I won’t go into detail here about the sequential rotation. The main point is 5>1 and 1>5 carousel
i represents the index of the current picture
pre represents the button of the previous picture
next represents the button of the next picture
ul represents the picture list
(1) 5>1>2... When the "next" button goes from 5 to 1, it rotates normally in order, and when the current picture is the second "1" , the next picture should be "2", then when "next", the left value of ul is 0, i==1;
(2) 1>5>4.... When When the "pre" button rotates from the current picture "1" (the first 1) to picture 5, i==4, the left value of ul becomes -5 times the width of img, that is, the first 1 is quietly Becomes the last 1;
is a bit confusing to express in language, here is the code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{padding: 0;margin: 0;} .container{ width: 273px;height: 163px;overflow: hidden; position: relative;margin: 0 auto; } .list{ position: absolute;width: 1638px;top: 0;left: 0px; } .list li{ float: left;list-style: none; } .btn{ position: absolute;display: block;width: 40px;height: 50px;font-size: 40px; text-align: center;font-weight: bold;top: 50%;margin-top: -25px;background-color: rgba(255,255,255,0.5);cursor:pointer; } .btn:hover{ background-color: rgba(0,0,0,0.3);color: #fff; } .pre{ left: 0; } .next{ right: 0; } .nav{ position: absolute;bottom: 5px;display: flex;justify-content: center;width: 100%; } .nav span{ width: 10px;height: 10px;border-radius: 10px;background-color: #fff;z-index: 2;display: inline-block;margin-right: 10px;cursor: pointer; } span.on{ background-color: orange; } </style> </head> <body> <p class="container"> <ul class="list" style="left: 0px"> <li><img src="/static/imghwm/default1.png" data-src="./images/1.png" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./images/2.png" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./images/3.png" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./images/4.png" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./images/5.png" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./images/1.png" class="lazy" alt=""></li> </ul> <p class="nav"> <span class="on"></span> <span></span> <span></span> <span></span> <span></span> </p> <em class="next btn">></em> <em class="pre btn"><</em> </p> <script type="text/javascript" src="../jquery.js"></script> <script type="text/javascript"> $(function(){ var i=0; $('.next').click(function(){ i++; console.log(i); moveImg(i); }); $('.pre').click(function(){ i--; moveImg(i); }); $('.nav span').click(function(){ var _index=$(this).index(); i=_index; moveImg(i); }); // i的作用:决定下一张图片是谁————也就是说ul的left是多少。 // $('.list').css({left)的值是从图a过度是此时的ul的left。 function moveImg(){ if (i==6) { i=1; $('.list').css({'left':'0'}); } // 是第一张 if(i==-1){ i=4; $('ul').css({left:(5*-273)}); } $('.list').stop().animate({'left':-273*i+'px'},1000); if (i==5) { $('.nav span').eq(0).addClass('on').siblings().removeClass('on'); } $('.nav span').eq(i).addClass('on').siblings().removeClass('on'); } }) </script> </body> </html>
The above is the detailed content of Example tutorial of seamless scrolling of js carousel chart. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


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

Dreamweaver Mac version
Visual web development tools

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

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
