Single picture pan switching implementation code
This article mainly introduces the js implementation of single picture translation switching effect in detail. After a picture is moved to the left, it is moved from the bottom back to the right and waits for the next cycle. Then let's study this article.
Since I don’t need the manual switching function, I deleted that part of the content, mainly to increase the seamless switching effect.
The principle is also very simple. After moving a picture to the left, it moves back to the right from the bottom and waits for the next cycle.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.1.min.js"></script> </head> <body> <p class="wrapper"> <h1>jquer实现图片切换</h1> <p id="focus"> <ul> <!-- 这里有三个z-index的设置 --> <li><p class="switch_pic" style="z-index: 3;background: url('imgs/01.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="z-index: 2;background: url('imgs/02.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="z-index: 1;background: url('imgs/03.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/04.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/meiko2.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/meiko7.jpg') center center;background-size: cover;"></p></li> </ul> </p> </p> <script type="text/javascript"> $(function() { var sWidth = $("#focus").width(); var len = $("#focus ul li").length; var index = 0; var picTimer; var $pics = $("#focus ul li").find('.switch_pic');//获取所有图片 showPics(index); //网页打开立即执行一次动画 picTimer = setInterval(function() { index++; if(index == len) {index = 0;} showPics(index); },3000);//3000毫秒的间隔 //显示图片函数,根据接收的index值显示相应的内容 function showPics(index) { //普通切换 var nowLeft = -sWidth; //每次移动固定量 var $pic = $pics.eq(index);//获取当前要移出的图片 var $nexPic = $pics.eq((index+1)%len);//当前要移入的图片 var $nexnexPic = $pics.eq((index+2)%len);//下一个要移入的图片 $nexPic.css("left",sWidth);//下一个图片移动到最右 //当前要移出的图片开始左移,模式设为平滑"linear",速度和间隔一样 $pic.animate({"left":nowLeft},3000,"linear",function(){ // 当前图片完全移出后,重新设置z-index $pic.css("z-index",1); $nexPic.css("z-index",3); $nexnexPic.css("z-index",2); }); //当前要移入的图片同时左移 $nexPic.animate({"left":0},3000,"linear"); } }); </script> <style type="text/css"> *{margin:0;padding:0;} body{font-size:12px;color:#222;font-family:Verdana,Arial,Helvetica,sans-serif;background:#f0f0f0;} .clearfix:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;} .clearfix{zoom:1;} ul,li{list-style:none;} img{border:0;} .wrapper{width:800px;margin:0 auto;padding-bottom:50px;} h1{height:50px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;margin-bottom:20px;} #focus{width:450px;height:350px;overflow:hidden;position:relative;} #focus ul{height:380px;position:absolute;} #focus ul li{float:left;width:450px;height:350px;overflow:hidden;position:absolute;background:#000;} #focus ul li p{position:absolute;overflow:hidden;width: 450px;height: 350px;} </style> </body>
Related recommendations:
JavaScript implements mouse wheel control page image switching
##js and Tutorial on implementing the css tag content switching function
Sharing of jQuery automatic or manual image switching implementation methods
The above is the detailed content of Single picture pan switching implementation code. 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

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Xiaomi 14Ultra is one of the most popular Xiaomi models this year. Xiaomi 14Ultra not only upgrades the processor and various configurations, but also brings many new functional applications to users. This can be seen from the sales of Xiaomi 14Ultra mobile phones. It is very popular, but there are some commonly used functions that you may not know yet. So how does Xiaomi 14Ultra switch between 4g and 5g? Let me introduce the specific content to you below! How to switch between 4g and 5g on Xiaomi 14Ultra? 1. Open the settings menu of your phone. 2. Find and select the "Network" and "Mobile Network" options in the settings menu. 3. In the mobile network settings, you will see the "Preferred network type" option. 4. Click or select this option and you will see

How to convert Win11 Home Edition to Win11 Professional Edition? In Win11 system, it is divided into Home Edition, Professional Edition, Enterprise Edition, etc., and most Win11 notebooks are pre-installed with Win11 Home Edition system. Today, the editor will show you the steps to switch from win11 home version to professional version! 1. First, right-click on this computer on the win11 desktop and properties. 2. Click Change Product Key or Upgrade Windows. 3. Then click Change Product Key after entering. 4. Enter the activation key: 8G7XN-V7YWC-W8RPC-V73KB-YWRDB and select Next. 5. Then it will prompt success, so you can upgrade win11 home version to win11 professional version.

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to switch between Apple dual systems when starting up Apple computers are powerful devices. In addition to their own macOS operating system, you can also choose to install other operating systems, such as Windows, to achieve dual system switching. So how do we switch between the two systems when booting? This article will introduce to you how to switch between dual systems on Apple computers. First of all, before installing dual systems, we need to confirm whether our Apple computer supports dual system switching. Generally speaking, Apple computers are based on

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.
