html5怎么点圆点切换图片,图片自动轮播+左右点击+圆点,手动切换后图片自动轮播就乱套了怎么改?...

test

body {

background: #f1f1f1;

}

a {

text-decoration: none;

}

img {

width: 320px;

height: 320px;

}

.container1 {

width: 320px;

height: 320px;

overflow: hidden;

margin: 100px auto;

position: relative;

}

.container1>a {

width: 20px;

height: 30px;

line-height: 30px;

position: absolute;

left: 0;

top: 150px;

color: rgba(0, 0, 0, 0.3);

font-size: 30px;

text-align: center;

}

.container1>a:nth-child(2) {

position: absolute;

left: 300px;

}

.container1>a:hover {

background: rgba(0, 0, 0, 0.3);

color: #fff;

}

.container1 .ui-page-item {

width: 100px;

height: 10px;

position: absolute;

bottom: 10px;

right: 20px;

display: flex;

flex-direction: row;

justify-content: space-between;

align-items: flex-end;

}

.container1 .ui-page-item span {

width: 5px;

height: 5px;

border: 2px solid rgba(255, 255, 255, 0.3);

background: rgba(0, 0, 0, 0.4);

border-radius: 50%;

transition: 0.2s;

}

.container1 .ui-page-item span:hover {

background: rgba(255, 255, 255, 0.4);

border-color: rgba(0, 0, 0, 0.4);

}

.active {

color: #fff10a;

font-size: 32px;

font-weight: 700;

}

var oCar = document.getElementById('carousel');

var oLeft = document.getElementById('oleft');

var oRight = document.getElementById('oright');

var oImg = document.getElementsByTagName('img')[0];

var arrUrl = ['http://i3.mifile.cn/a4/3d43e725-326f-43e1-a373-c49eabf52b21', 'http://i3.mifile.cn/a4/73af3040-727c-4b5d-846f-6e0d60db86a1', 'http://i3.mifile.cn/a4/fd65a053-4b78-4159-a866-72d51f63900c', 'http://i3.mifile.cn/a4/2bffe653-bd4f-44b1-8332-8fac13f2d66e', 'http://i3.mifile.cn/a4/5ee09922-333b-40cd-bf40-792d743419fa'];

var aSpan = document.getElementsByTagName('span');

var num = 0;

//定時器

var timer = setInterval(function() {

num++;

num %= arrUrl.length;

fnTab();

}, 3000);

// 有用戶來操作的定時器,開啟之前一定要先關

oCar.onmouseover = function() {

clearInterval(timer);

}

oCar.onmouseout = function() {

timer = setInterval(function() {

num++;

num %= arrUrl.length;

fnTab();

}, 3000);

};

// 初始化

function fnTab() {

oImg.src = arrUrl[num];

for(var i = 0; i < aSpan.length; i++) {

aSpan[i].className = '';

}

aSpan[num].className = 'active';

}

fnTab();

//鼠標放上去顯示本塊內容

for(var i = 0; i < aSpan.length; i++) {

aSpan[i].index = i;

// 索引值

aSpan[i].onmouseover = function() {

num = this.index;

fnTab();

}

}

// 左右轮播点击事件

oLeft.onclick = function() {

num--;

if(num == -1) {

num = arrUrl.length - 1

}

fnTab();

}

oRight.onclick = function() {

num++

if(num == arrUrl.length) {

num = 0

}

fnTab();

}

clearInterval才行 clearTimeout没用,都是细节问题,注意下就好

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值