<div id
="ad">
<!--图片
-->
<ul
>
<li
class="show"><a href
="#"><img src
="images/a.jpg"></a
></li
>
<li
><a href
="#"><img src
="images/b.jpg"></a
></li
>
<li
><a href
="#"><img src
="images/c.jpg"></a
></li
>
<li
><a href
="#"><img src
="images/d.jpg"></a
></li
>
</ul
>
<!--小圆点
-->
<p
>
<span
class="show" title
="0"></span
>
<span title
="1"></span
>
<span title
="2"></span
>
<span title
="3"></span
>
</p
>
</div
>
var img
=document
.querySelectorAll("#ad li");
var span
=document
.querySelectorAll("#ad span");
var count
=0;
var timer
=setInterval(task
,1000);
function task(){
img
[count
].className
="";
span
[count
].className
="";
count
++;
if(count
==img
.length
)count
=0;
img
[count
].className
="show";
span
[count
].className
="show";
}
var ad
=document
.getElementById("ad");
ad
.onmouseover=function(){
clearInterval(timer
);
timer
=null;
}
ad
.onmouseout=function(){
timer
=setInterval(task
,1000);
}
for(var i
=0;i
<span
.length
;i
++){
span
[i
].onmouseover=function(){
for(var j
=0;j
<span
.length
;j
++){
if(this==span
[j
]){
if(count
!=j
){
img
[count
].className
="";
span
[count
].className
="";
count
=j
;
img
[count
].className
="show";
span
[count
].className
="show";
}
break;
}
}
}
}
ul
{margin
: 0;padding
: 0;}
#ad
{
width
: 480px
;
height
: 360px
;
position
: relative
;
}
#ad li
{
list
-style
: none
;
position
: absolute
;
left
: 0;
top
: 0;
opacity
: 0;
transition
: all
1s
;
}
#ad p
{
position
: absolute
;
left
: 0;
bottom
: 30px
;
width
: 100%;
text
-align
: center
;
}
#ad p span
{
display
: inline
-block
;
width
: 14px
;
height
: 14px
;
border
-radius
: 50%;
background
: #
999;
cursor
: pointer
;
}
#ad li
.show
{
opacity
: 1;
}
#ad p span
.show
{
background
: #fff
;
}
转载请注明原文地址: https://mac.8miu.com/read-62036.html