Blogger Information
Blog 47
fans 0
comment 3
visits 44736
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
轮播图自动翻页功能实现
江流
Original
869 people have browsed it

轮播图的自动翻页功能是将click事件派发给下一页按钮,并且这种派发,没隔2秒钟执行一次,从而实现自动翻页的功能。

  1. // 自动翻页
  2. // 定义一个click的事件对象
  3. const autoTurn = new Event("click");
  4. //获取下一页按钮
  5. const next = document.querySelector(".skip .next");
  6. //每隔2秒执行一次,将click事件派发给next按钮
  7. setInterval(() => next.dispatchEvent(autoTurn), 2000);
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post