JS implementation method of Taobao slideshow effect_javascript skills
Implementation ideas:
1. The for loop adds click events to the number buttons.
2. The for loop first clears the button's style, and then sets the current style.
3. Add a custom attribute index aBtn[i].index=i aBtn[2]=2 to each button. If you want the second button to correspond to the second picture, use a motion frame to change the UL of the large picture each time. Move -150px because the image height is 150px. If you move to the nth picture, it is -150*n.
4. Define the variable now for automatic playback. Assign the current image to now now=this.index.
5. Define the autoplay function. now Next picture, if judgment, when reaching the last picture, set now to 0, which is the first picture. if(now==aBtn.length)
6. Define a timer and call the autoplay function every 2 seconds.
7. Clear the timer when the mouse points to the picture.
8. The timer starts when the mouse leaves the picture.
<script><BR> window.onload=function ()<BR> {<BR> var oDiv=document.getElementById('play');<BR> var aBtn=oDiv.getElementsByTagName('ol')[0].getElementsByTagName('li');<BR> var oUl=oDiv.getElementsByTagName('ul')[0];<BR> var now=0;<br><br> for(var i=0;i<aBtn.length;i )<BR> {<BR> aBtn[i].index=i;<BR> aBtn[i].onmouseover=function()<BR> {<BR> now=this.index; //The current value is assigned to now<BR> tab();<BR> }<BR> };<br><br> function tab()<BR> { for(var i=0;i<aBtn.length;i) <BR> {<BR> aBtn[i ; -150*now}); //Use the motion framework to set UL's TOP to the current number*-150. The third picture is 2*-150<BR> };<BR><BR> function next()<BR> One piece<BR> }<br> tab(); //Pull the picture back to the first one and continue moving<br> };<BR><BR> var timer=setInterval(next,2000); //2 seconds Automatically switch pictures<BR><BR> oDiv.onmouseover=function()<BR> {<BR> clearInterval(timer); //Clear timer<BR> };<BR><br> oDiv.onmouseout=function( ; <br>Full code:<br><br><BR><BR><BR>Copy code<br><br><BR> The code is as follows:<BR><div class="codebody" id="code52143"><BR><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><BR> <html xmlns="http://www.w3.org/1999/xhtml"><BR> <head><BR> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><BR> <title>淘宝幻灯片上下滑动效果 —— www.zhinengshe.com —— 智能课堂<BR> <link href="css.css" rel="stylesheet" type="text/css" /><BR> <script src="baseCommon.js"></script>
<script><BR> window.onload=function()<BR> {<BR> var oDiv=document.getElementById('play');<BR> var aBtn=oDiv.getElementsByTagName('ol')[0].getElementsByTagName('li');<BR> var oUl=oDiv.getElementsByTagName('ul')[0];<BR> var now=0;<br><br> for(var i=0;i<aBtn.length;i )<BR> {<BR> aBtn[i].index=i;<BR> aBtn[i].onmouseover=function()<BR> {<BR> now=this.index; //当前值赋给now<BR> tab();<BR> }<BR> };<br><br> function tab()<BR> { <BR> for(var i=0;i<aBtn.length;i ) <BR> {<BR> aBtn[i].className=''; //把所有按钮的样式清空<BR> };<BR> aBtn[now].className='active'; //当前按钮样式设置<BR> startMove(oUl,{top:-150*now}); //用运动框架把UL的TOP设置为当前个数*-150,第三张图片就是2*-150<BR> };<br><br> function next()<BR> {<BR> now ; //切换图片<BR> if(now==aBtn.length) //如果到了最后一张图片<BR> {<BR> now=0; // 把图片拉回第一张<BR> }<BR> tab(); //把图片拉回第一张后继续运动<BR> };<br><br> var timer=setInterval(next,2000); //2秒自动切换图片<br><br> oDiv.onmouseover=function()<BR> {<BR> clearInterval(timer); //清除定时器<BR> };<br><br> oDiv.onmouseout=function()<BR> {<BR> timer=setInterval(next,2000); //开启定时器<BR> };<BR> };<BR> </script>

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.

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.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.

How to send task notifications in Quartz In advance When using the Quartz timer to schedule a task, the execution time of the task is set by the cron expression. Now...

How to obtain the parameters of functions on prototype chains in JavaScript In JavaScript programming, understanding and manipulating function parameters on prototype chains is a common and important task...

Analysis of the reason why the dynamic style displacement failure of using Vue.js in the WeChat applet web-view is using Vue.js...

How to make concurrent GET requests for multiple links and judge in sequence to return results? In Tampermonkey scripts, we often need to use multiple chains...


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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.