In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you about how JavaScript implements the carousel graph. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Use a simple rotation diagram written by the timer, and look directly at the code, as follows:
1.css code
* {margin: 0; padding: 0; box-sizing: border-box;} body {font-size: 14px; font-family: Arial, Helvetica, sans-serif;}. Slider-box {width: 1226px; height: 460px; margin: 10px auto; overflow: hidden; position: relative } .slider-box .images a {width: 100%; height: 460px; position: absolute; left: 0; top: 0; opacity: 0; transition: all 2s;} .slider-box .images a.active {opacity: 1;} .slider-box .images an img {width: 100% Height: 100%; display: block;}. Slider-box .nav {position: absolute; left: 0; top: 195px; width: 100%; / * background-color: red; * / padding: 0 10px; / * height: 100px * /} .slider-box .nav a {background-image: url (img/icons.png); width: 41px; height: 69px; display: inline-block; background-repeat: no-repeat;} .slider-box .nav .prev {background-position:-84px 0 } .slider-box .nav .prev: hover {background-position: 00;} .slider-box .nav. Next {background-position:-125px 0; float: right;} .slider-box .nav. Next: hover {background-position:-42px 0;} .slider-box .pages {position: absolute Right: 20px; bottom: 25px; font-size: 0; width: 1186px; text-align: center; / * background-color: rebeccapurple; * /} .slider-box .pages .dot {display: inline-block; width: 10px; height: 10px; border-radius: 50% Background-color: rgba; margin-right: 10px;} .slider-box .pages .dot: hover {background-color: yellow;} .slider-box .pages .dot.active {background-color: yellow;}
2.html code
3.js code
/ / var images = document.querySelectorAll ('.images a') var index = 0 / / defines the index of the picture to be played var pages = document.querySelectorAll (".dot") var prev = document.querySelector (".prev") var next = document.querySelector (".next") / / switch the picture according to the index value / / find the a tag of images Add the class active function showImage (idx) {images.forEach (function (v) I) {/ / idx = 1 / / I = 0 1234 if (i===idx) {v.classList.add ('active') / / Control the corresponding point highlights pages [I] .classList.add ("active")} else { V.classList.remove ('active') pages [I] .classList.remove ("active")})} / / showImage (3) prev.onclick = function () {if (index===0) {index= images.length-1 pick / 4} else {index= index -1} showImage (index)} next.onclick = function () {if (index===images.length-1) {index= 0} else {index+=1} showImage (index)} var timer = setInterval (function () {/ / timer controls the switching of the picture as well as clicking the next one / / call the next click action next.click () / / simulate the click action of next} 3000) Thank you for reading! This is the end of the article on "how to realize the JavaScript broadcast map". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.