本文主要和大家分享jq和css自制轮播效果代码,希望能帮助到大家。
html部分:
<p> </p><p> <a>@@##@@</a> <a>@@##@@</a> <a>@@##@@</a> </p> <!-- 图片盒子 end --> <p> <span>这是我定义的第一张图</span> <span>这是我定义的第二张图</span> <span>这是我定义的第三张图</span> </p>
css部分:
.banner1 {
width: 100%;
height: 4rem;
overflow: hidden;
margin: 0 auto;
position: relative;
}
.imgbox1 {
height: 7.5rem;
position: absolute;
left: 0;
overflow: hidden;
background: #fff;
}
.imgbox1 img {
width: 100%;
float: left;
}
.title1 {
width: 100%;
position: absolute;
bottom: 0px;
padding: .25rem .2rem;
box-sizing: border-box;
background: rgba(255, 255, 255, 0.8);
}
.title1>span {
color: #000000;
display: block;
text-align: center;
}
.circle1 {
width: 1.5rem;
margin: .2rem auto 0;
}
.circle1 li {
width: .2rem;
height: .2rem;
margin: .1rem 5px;
cursor: pointer;
display: inline-block;
background: #CCCCCC;
border-radius: 50%;
}
.circle_active {
background: #575757 !important;
}
js部分:
var imgindex=$('.imgbox1').find('a').index()
var titleindex=$('.title1').find('span').index();
$(window).ready(function(){
$('.title1').find('span').eq(0).show();
$('.title1').find('span').eq(0).siblings().hide();
})
$('.circle1').on('click','li',function(){
var circleindx=$(this).index();
imgindex=circleindx;
titleindex=circleindx;
$(this).addClass('circle_active');
$(this).siblings().removeClass('circle_active');
$('.imgbox1').find('a').eq(imgindex).show(300);
$('.imgbox1').find('a').eq(imgindex).siblings().hide();
$('.title1').find('span').eq(titleindex).show();
$('.title1').find('span').eq(titleindex).siblings().hide();
})
function autoplay(){
timer=setInterval(function(){
imgindex++;
var circles=$('.circle1').find('li');
if(imgindex>circles.length-1){
imgindex=0;
}
circles.eq(imgindex).trigger("click");
},2000);
}
autoplay()
相关推荐:
react轮播图组件react-slider-light详解
htmlq 是一个命令行工具,使用 CSS 选择器从 HTML 中提取内容,相当于 jq 的 HTML 版本。该工具使用 Rust 编写,允许你通过 CSS 选择器将 HTML 管道化,直接从终端提取文本、属性和结构化内容。
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










