为什么我的轮播会一次性播完三张图片呢
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!DOCTYPE html> < html > < head > < meta charset = "utf-8" /> < meta name = "viewport" content = "width=device-width, initial-scale=1" > < title ></ title > < link rel = "stylesheet" type = "text/css" href = "css/style.css" /> </ head > < body > < div class = "main" id = "main" > < div class = "banner" id = "banner" > < a href = "" > < div class = "banner-slide slide1 slide-active" ></ div > </ a > < a href = "" > < div class = "banner-slide slide2" ></ div > </ a > < a href = "" > < div class = "banner-slide slide3" ></ div > </ a > </ div > < div > < a href = "javascript:void(0)" class = "button prev" ></ a > < a href = "javascript:void(0)" class = "button next" ></ a > < div class = "dots" > < span class = "active" ></ span > < span ></ span > < span ></ span > </ div > </ div > </ div > < script src = "js/script.js" ></ script > </ body > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | * { margin : 0px ; padding : 0px ; } ul{ list-style : none ; } body{ font-family : "微软雅黑" ; color : #14191e ; } .main{ width : 1200px ; height : 460px ; margin : 30px auto ; overflow : hidden ; position : relative ; } .banner{ width : 1200px ; height : 460px ; overflow : hidden ; position : relative ; } .banner-slide{ width : 1200px ; height : 460px ; position : absolute ; background-repeat : no-repeat ; display : none ; } .slide-active{ display : block ; } .slide 1 { background-image : url (../img/bg 1 .jpg); } .slide 2 { background-image : url (../img/bg 2 .jpg); } .slide 3 { background-image : url (../img/bg 3 .jpg); } .button{ position : absolute ; width : 40px ; height : 80px ; left : 244px ; top : 50% ; margin-top : -40px ; background : url (../img/arrow.png) no-repeat center center ; } .button:hover{ background-color : #333 ; opacity: 0.5 ; } .prev{ transform: rotate( 180 deg); } .next{ left : auto ; right : 0 ; } .dots{ position : absolute ; right : 0 ; bottom : 24px ; text-align : right ; } .dots span{ display : inline- block ; height : 12px ; width : 12px ; border-radius: 50% ; background : rgba( 1 , 17 , 27 , 0.4 ); margin-right : 8px ; box-shadow: 0 0 2px 2px rgba( 255 , 255 , 255 , 0.8 ) inset ; /* border: 1px solid white ; */ cursor : pointer ; } .dots span.active{ box-shadow: 0 0 0 2px rgba( 7 , 17 , 27 , 0.4 ) inset ; background : #fff ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | function byId(id) { return typeof (id) === "string" ? document.getElementById(id) : id; } var index = 0; timer = null ; pics = byId( "banner" ).getElementsByTagName( "div" ); len = pics.length; function slideImg() { var main = byId( "main" ); main.onmouseover = function () { } main.onmouseout = function () { timer = setInterval( function () { if (index >= len) { index = 0; } changeImg(); index++; }, 2000); } } function changeImg(){ for ( var i=0;i<len;i++){ pics[i].style.display= 'none' ; } pics[index].style.display= 'block' ; console.log(index); } slideImg(); |
8
收起
正在回答
1回答
同学你好,一开始轮播图是正常运转的,当鼠标滑过时,才会出现一次性播完三张图片的问题,
同学在js中添加这句代码试试:
在没加这句话之前,同学可以看一下,在3-5 图片的自动轮播和停止课程中,老师的2分45秒左右,也会出现同学出现的这个问题
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
2. 从网页搭建入门JavaWeb
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧