// 获取控件
const sliderItem=document.querySelectorAll('#d1>.slider-item');
const xyd=document.querySelectorAll('#xyd>span');
console.log(xyd);
// 定时器
setInterval(() => {
// 遍历控件数组中的元素
for(let i=0;i<sliderItem.length;i++){
if(sliderItem[i].className='slider-item'&&xyd[i].className==''){
sliderItem[i].className+=' slider-item-active';
xyd[i].className='active';
}
sliderItem[i].className='slider-item';
xyd[i].className='';
}
}, 1000);
<!-- 第一种切换方式 -->
<div class="banner demo">
<h3>自动或点击小圆点切换图片</h3>
<div class="slider-layout">
<div class="banner-slider slider">
<div class="slider-content" id="d1">
<div class="slider-item slider-item-active"><img src="img/banner01.png" alt=""></div>
<div class="slider-item"><img src="img/banner02.png" alt=""></div>
<div class="slider-item"><img src="img/banner03.png" alt=""></div>
</div>
<div class="dots pagination" id="xyd">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
</div>
</div>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星