


Implementing left and right image carousels based on jQuery (general principle)_jquery
This article shares the jQuery code for implementing left and right image carousels for your reference. The specific implementation content is as follows
Operation rendering:
Point! ! !
Implementation principle:
Determine whether the image is moved left or right by judging the change in the index value. By controlling the left value of the image, a carousel effect is achieved.
Specific code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <script src="js/jquery.min.js"></script> <style> .banner{ margin:0 auto; border: 4px dashed black; width:400px; height:200px; position: relative; overflow:hidden; } .banner a{ z-index: 100; display: block; width:100%; height: 100%; position: absolute; left:100%; top:0; } .banner .first{ left:0; } .banner a img{ width:100%; height: 100%; } .choose{ z-index: 1000; position: absolute; left:150px; top:180px; width:100px; height: 10px; } .choose span{ margin-right: 15px; float: left; display:block; background: blue; width:10px; height: 10px; border-radius: 10px; } .choose span:hover{ background: red; } .choose .red{ background: red; } .banner .pre,.next{ cursor:pointer; text-align:center; border-radius:20px; display:block; background:#cccccc; opacity:0.4; text-decoration: none; z-index: 200; display:block; width:40px; height: 40px; font-size: 40px; color:red; position: absolute; top:80px; } .banner .pre{ left:0px } .banner .next{ right: 0px; } </style> <body> <div class="banner"> <!-- 这里为上一页下一页点击按钮 --> <span class="pre">-</span> <span class="next">+</span> <!-- 此处为轮播主体,颜色块代替。图片自加 --> <a href="###" class="first" style="background: pink;"></a> <a href="###" style="background: blue;"><img src="/static/imghwm/default1.png" data-src="images/banner1.jpg" class="lazy"/ alt="Implementing left and right image carousels based on jQuery (general principle)_jquery" ></a> <a href="###" style="background: greenyellow;"><img src="/static/imghwm/default1.png" data-src="images/banner2.jpg" class="lazy"/ alt="Implementing left and right image carousels based on jQuery (general principle)_jquery" ></a> <a href="###" style="background: deepskyblue;"><img src="/static/imghwm/default1.png" data-src="images/banner3.jpg" class="lazy"/ alt="Implementing left and right image carousels based on jQuery (general principle)_jquery" ></a> <!-- 此处为轮播部分下方小点选择 --> <div class="choose"> <span class="red"></span> <span></span> <span></span> <span></span> </div> </div> <script> /*定义两个变量,保存当前页码和上一页页码*/ var $index=0; var $exdex=0; /*小点的鼠标移入事件,触发图片左移还是右移*/ $(".choose span").mouseover(function(){ //获取当前移入的index值 $index=$(this).index(); //首先让点的颜色变化,表示选中 $(".choose span").eq($index).addClass("red").siblings(). removeClass("red"); //判断如果index变小,证明图片要往左移动。变大则为右移 if($index>$exdex){ next(); }else if($index<$exdex){ pre(); } //移动完毕将当前index值替换了前页index return $exdex=$index; }); //下一页的点击事件。在右移基础上加了最大index判断 $(".next").click(function(){ $index++; if($index>3){ $index=0 } $(".choose span").eq($index).addClass("red").siblings(). removeClass("red"); next(); return $exdex=$index; }); //上一页的点击事件 $(".pre").click(function(){ $index--; if($index<0){ $index=3 }; $(".choose span").eq($index).addClass("red").siblings(). removeClass("red"); pre(); return $exdex=$index; }); //加个定时器,正常轮播 var atime=setInterval(function(){ $(".next").click(); },1000); //这里为右移和左移的事件函数。 //右移基本原理就是先让exdex定位的left左移百分百,而选中的当前页从屏幕右边移入,left变为0 function next(){ $(".banner a").eq($index).stop(true,true). css("left","100%").animate({"left":"0"}); $(".banner a").eq($exdex).stop(true,true). css("left","0").animate({"left":"-100%"}); } function pre(){ $(".banner a").eq($index).stop(true,true). css("left","-100%").animate({"left":"0"}); $(".banner a").eq($exdex).stop(true,true). css("left","0").animate({"left":"100%"}); } </script> </body> </html>
The above is the entire content of this article to help you achieve a simple and elegant image carousel effect.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

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.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool