当前位置: 首页 > news >正文

JS轮播图实现自动轮播、悬浮停止轮播、点击切换,下方指示器与图片联动效果

代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.context{width: 600px;margin: 0 auto;text-align: center;}.context img{width: 600px;height: 300px;}.container{position: relative;}.yuan{width: 50px;height: 50px;position: absolute;right: 0;top: 43%;line-height: 46px;font-size: 28px;font-weight: bold;background-color: white;border: 1px solid black;border-radius: 50px;color: black;opacity: 0.5;display: none;cursor: pointer;}.leftyuan{width: 50px;height: 50px;position: absolute;left: 0;top: 43%;line-height: 46px;font-size: 28px;font-weight: bold;background-color: white;border: 1px solid black;border-radius: 50px;color: black;opacity: 0.5;display: none;cursor: pointer;}ul li{list-style: none;float: left;margin: 0 10px;width: 35px;height: 30px;line-height: 30px;background-color: #eeeeee;cursor: pointer;}ul{position: absolute;bottom: 0;left: 21%;}li:hover{background-color: #fea500}.orange{background-color: #fea500;}</style>
</head>
<body><div class="context">  <div class="container"><img src="./image/1.jpg" alt=""><div class="yuan">></div><div class="leftyuan"><</div><ul><li class="orange">1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul></div><!-- <button>上一张</button><button>下一张</button> --></div><script>let btns = document.querySelectorAll('button')let simg = document.querySelector('img')let container = document.querySelector('.container')let yuan = document.querySelector('.yuan')let leftyuan = document.querySelector('.leftyuan')let li = document.querySelectorAll('ul li')let b=0li.forEach(item=>{item.onclick=function(){simg.src=`./image/${item.innerText}.jpg`jx(item.innerText)}})// 控制图片变化变量let d1=setInterval(djq,1000)function djq(){// clearInterval(d1)if(b==5){b=0}simg.src=`./image/${++b}.jpg`li.forEach(item=>{item.classList.remove('orange')if(b==item.innerHTML){item.classList.add('orange')}})if(b==5){b=0}}function jx(c){b=cclearInterval(d1)simg.src=`./image/${b}.jpg`li.forEach(item=>{item.classList.remove('orange')if(b==item.innerHTML){item.classList.add('orange')}})if(b==5){b=0}}yuan.onclick=function(){if(b>=5){b=0}simg.src=`./image/${++b}.jpg`li.forEach(item=>{item.classList.remove('orange')if(b==item.innerHTML){item.classList.add('orange')}})}leftyuan.onclick=function(){if(b<=1){b=6}simg.src=`./image/${--b}.jpg`li.forEach(item=>{item.classList.remove('orange')if(b==item.innerHTML){item.classList.add('orange')}})}container.onmouseenter= function(){clearInterval(d1)yuan.style.display='block'leftyuan.style.display='block'}container.onmouseleave= function(){// console.log('b');d1 =setInterval(djq,1000)yuan.style.display='none'leftyuan.style.display='none'}// btns[0].onclick=function(){//     if(b<=1){//         b=6//     }//     simg.src=`./image/${--b}.jpg`// }// btns[1].onclick=function(){//     if(b>=5){//         b=0//     }//     simg.src=`./image/${++b}.jpg`// }</script>
</body>
</html>

效果图:

注:需要自己找5张图片下载到image文件夹下,并且把图片名字改成1到5哦

如下图所示:


http://www.mrgr.cn/news/58495.html

相关文章:

  • IO多路复用小项目day01 ———— c语言版本
  • linux设置某些文件开机自启动
  • Debian及其衍生系统安装Python
  • 电脑文件共享后网络列表下没有出现共享用户
  • 面试官:你会如何设计QQ中的网络协议?
  • Django+Vue全栈开发旅游网项目首页
  • 【人工智能】——matplotlib教程
  • 广州企业管理咨询公司排名前十
  • 大尺寸反射式液晶显示模块行业分析:预计2030年全球市场规模将达到2,020.21百万美元
  • echarts给Y轴的不同轴线设置不同的颜色的样式
  • 【OpenAI】第二节(Token)关于ChatGPT的Token你了解多少?最全Token讲解过程!
  • SpringMVC8-HttpMessageConverter
  • 《企业自设2-软件测试》搭建locust环境+使用它搜索百度接口
  • 在Flutter中实现排行榜滑动阻尼效果
  • 大家都在用的HR招聘管理工具:国内Top5排名
  • 免费开源!语音识别平台让医疗对话更高效,沟通更准确
  • xtu oj 字母序列
  • 时间数据可视化基础实验(南丁格尔玫瑰图)——Python热狗大胃王比赛数据集
  • 网站建设中需要注意哪些安全问题?----雷池社区版
  • 达梦数据库基本操作指南:从表空间创建到触发器应用
  • K8S部署
  • 从设计到伴飞:数字孪生赋能航天航空新时代
  • 大模型日报|12 篇必读的大模型论文
  • 放电消纳负载是什么
  • 前端经典【面试题】持续更新HTML、CSS、JS、VUE、FLUTTER、性能优化等
  • 探索自然之美:SpringBoot驱动的安康旅游网站开发