首页 > web前端 > js教程 > 正文

jq和css自制轮播效果代码分享

小云云
发布: 2018-02-28 10:14:40
原创
1318 人浏览过

本文主要和大家分享jq和css自制轮播效果代码,希望能帮助到大家。

html部分:

<p class="banner1">
<p class="imgbox1">
<a href="#"><img src="img/detail1.jpg" alt="这是我定义的第一张图"></a>
<a href="#"><img src="img/project1.png" alt="这是我定义的第二张图"></a>
<a href="#"><img src="img/aboutus.png" alt="这是我定义的第三张图"></a>
</p>
<!-- 图片盒子 end -->
<p class="title1">
<span>这是我定义的第一张图</span>
<span>这是我定义的第二张图</span>
<span>这是我定义的第三张图</span>
</p>
</p>
<ul class="circle1">
<li class="circle_active"></li>
<li></li>
<li></li> 
</ul><!-- 圆点下标 end -->
登录后复制

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=$(&#39;.imgbox1&#39;).find(&#39;a&#39;).index()
                var titleindex=$(&#39;.title1&#39;).find(&#39;span&#39;).index();
                $(window).ready(function(){
                
$(&#39;.title1&#39;).find(&#39;span&#39;).eq(0).show();
                
$(&#39;.title1&#39;).find(&#39;span&#39;).eq(0).siblings().hide();
                })
$(&#39;.circle1&#39;).on(&#39;click&#39;,&#39;li&#39;,function(){
var circleindx=$(this).index();
imgindex=circleindx;
titleindex=circleindx;
$(this).addClass(&#39;circle_active&#39;);
$(this).siblings().removeClass(&#39;circle_active&#39;);
$(&#39;.imgbox1&#39;).find(&#39;a&#39;).eq(imgindex).show(300);
$(&#39;.imgbox1&#39;).find(&#39;a&#39;).eq(imgindex).siblings().hide();
$(&#39;.title1&#39;).find(&#39;span&#39;).eq(titleindex).show();
$(&#39;.title1&#39;).find(&#39;span&#39;).eq(titleindex).siblings().hide();
    })
    function autoplay(){      
timer=setInterval(function(){
  imgindex++;
  var circles=$(&#39;.circle1&#39;).find(&#39;li&#39;);
  if(imgindex>circles.length-1){                  
imgindex=0; 
      }               
  circles.eq(imgindex).trigger("click");       
},2000); 
}       
                autoplay()
登录后复制

相关推荐:

react轮播图组件react-slider-light详解

JS实现图片轮播的实例

jquery实现PC端轮播图代码

以上是jq和css自制轮播效果代码分享的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!