


Detailed explanation of the steps to implement seamless carousel and left and right clicks with jQuery
This time I will bring you a detailed explanation of the steps for jQuery to achieve seamless carousel and left and right clicks. What are the precautions for jQuery to implement seamless carousel and left and right clicks. Here are practical cases. Let’s take a look. one time.
There are many, many seamless carousel left and right loops that we want in the web page. This is my first carousel effect, and it is also the most basic. I would like to share it with you. For beginners, I hope you can To learn from it, I want you to abuse me and give me your valuable opinions.
This is the effect I want
Let’s get to the point. First is the layout. The principle of layout is to create the ul tag in p and insert the li tag in ul. , insert pictures in, if you want several pictures to rotate, insert several li. The main point in the layout is to set the size of p, add overflow: hidden; to hide the excess part, the length of ul is the total length of all pictures, and li is floating.
html code
<p id="djlb"> <p id="bigul"> <ul> <li> <img src="../images/djlb1.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> <ul> <li> <img src="../images/djlb2.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> <ul> <li> <img src="../images/djlb3.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> <ul> <li> <img src="../images/djlb2.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> <ul> <li> <img src="../images/djlb2.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> <ul> <li> <img src="../images/djlb2.gif" alt=""> <p class="zt4">赵茜</p> <p class="zt22">北京大学历史系研究生</p> </li> <li> <img src="../images/yc2.gif" alt="yc2"> </li> </ul> </p> </p> <p id="aniu"> <p id="bleft"></p> <p id="bright"></p> </p> </p>
css code
#djlb { width: 1200px; height: 600px; overflow: hidden; } #bigul { width: 1800px; height: 560px; } #bigul > ul { position: relative; width: 300px; height: 560px; float: left; } #bigul > ul > li:nth-child(even) { position: absolute; display: none; } #bigul > ul > li { width: 300px; height: 560px; float: left; } #aniu { position: relative; } #aniu > p { position: absolute; } #aniu > p:first-child{ left:-55px; top: -290px; display: inline-block; border-left: 6px solid #c2c2c2; border-top: 6px solid #c2c2c2; width: 37px; height: 37px; transform: rotate(-45deg); } #aniu > p:last-child{ left: 1210px; top: -290px; display: inline-block; border-right: 6px solid #c2c2c2; border-bottom: 6px solid #c2c2c2; width: 37px; height: 37px; transform: rotate(-45deg); } #aniu > p:first-child:hover{ border-left: 6px solid #ffcc00; border-top: 6px solid #ffcc00; } #aniu > p:last-child:hover { border-right: 6px solid #ffcc00; border-bottom: 6px solid #ffcc00; }
Mainly explain my js idea;
$(function () { var i = 0, tick, list, ul = $("#bigul"); $("#bright").click(function () { $("#bigul").animate({ "margin-left": -300 }, 30000, function () {//当你执行完了后发生的事件 list =ul.find("ul"); //正常的话ul就是li,因为我这个需要鼠标浮动显示隐藏,结构一样 ul.append(list.first()); //ul追加到最后一个 ul.css("margin-left",0); //在每一次点击过后,margin-left初始化为零,为什么嘛要初始化呢? 思考一下? });//这样就向右无限循环了,就像队列一样 if (tick) { clearTimeout(tick); } //清除上一次定时器 tick = setTimeout(function () { $("#bright").click(); }, 30000); 定时器自动的部分 }); $("#bleft").click(function(){ list = ul.find("ul"); list.last().insertBefore(list.first()); // 当第一次点击时,把最后的搬到前面来, ul.css("margin-left",-300); ul.animate({ "margin-left": 0 }, 3000); //同样这个问题?? if (tick) { clearTimeout(tick); } tick = setTimeout(function () { $("#bleft").click(); }, 3000); }); $("#bright").click(); //自动向右事件 });
Now let me tell you why, if it is not initialized, you When you click on the right side, it will copy the first to the third picture, because when you move the first one to the next one, the left side of the ul parent box is 0, and the next time you move it, it will automatically complete its position, that is There are two positions, so it’s the third picture directly. I figured it out only by drawing the picture hehe!
The whole idea:
Use animate to move li,
When you click to the right, use the append() method Add the first card to the last card, and clear it every time you move it.
When you click to the left, use insertBefore() to insert the last picture into the first picture, and also clear it
tick is the timer settimeout we defined
The last sentence It is an automatic right event.
Mouse movement, display and hiding are all done using mouseout() and show(), hide().
I believe you have mastered the method after reading the case in this article. For more exciting content, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Solving node modifications How to deal with frequent manual restarts
The above is the detailed content of Detailed explanation of the steps to implement seamless carousel and left and right clicks with jQuery. For more information, please follow other related articles on the PHP Chinese website!

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











Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:
