手风琴风格图片轮播

今天在http://www.w3cfuns.com/notes/20618/7af828f7b6b7f9d1bb127a9cfbb3267c上看到这个效果,所以拿来练练手,太久没动脑子了,得让它活动活动。

轮播效果:

在该文章的基础上,我自己添加了自动轮播的效果

  1 <!DOCTYPE HTML>
  2 <html>
  3 <head>
  4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5     <title>手风琴切换</title>
  6 </head>
  7 <style type="text/css">
  8     .ts {
  9         overflow: hidden;
 10         width: 1072px;
 11         margin: 0 auto;
 12     }
 13     .ts-ul {
 14         overflow: hidden;
 15         width: 100%;
 16         height: 500px;
 17         margin: 0 auto;
 18         padding: 0;
 19     }
 20     .ts-ul li {
 21         list-style-type: none;
 22         overflow: hidden;
 23         float: left;
 24         width: 95px;
 25         -webkit-transition: width 0.5s;
 26     }
 27     .ts-ul b {
 28         -webkit-transition: all 0.5s;
 29         width: 95px;
 30         display: block;
 31         height: 440px;
 32         text-indent: -9999em;
 33         background: url(http://gyc.woniu.com/tg/ad6/images/ts.jpg);
 34     }
 35 
 36     .ts-ul-li1 {
 37         background: url(http://gyc.woniu.com/tg/ad6/images/ts1_on.jpg) no-repeat;
 38     }
 39 
 40     .ts-ul-li2 {
 41         background: url(http://gyc.woniu.com/tg/ad6/images/ts2_on.jpg) no-repeat;
 42     }
 43 
 44     .ts-ul-li3 {
 45         background: url(http://gyc.woniu.com/tg/ad6/images/ts3_on.jpg) no-repeat;
 46     }
 47     .ts-ul-li4 {
 48         background: url(http://gyc.woniu.com/tg/ad6/images/ts4_on.jpg) no-repeat;
 49     }
 50     .ts-ul li.on {
 51         width: 787px;
 52     }
 53     .ts-ul li.on b{
 54         opacity: 0;
 55         filter: Alpha(opacity=0);
 56     }
 57     .ts-ul-li1 b {
 58         background-position: 0 0
 59     }
 60     .ts-ul-li2 b {
 61         background-position: -95px 0
 62     }
 63     .ts-ul-li3 b {
 64         background-position: -190px 0
 65     }
 66     .ts-ul-li4 b {
 67         background-position: -285px 0
 68     }
 69 </style>
 70 
 71 <body>
 72     <div class="ts">
 73         <ul class="ts-ul">
 74             <li class="ts-ul-li1"><b></b></li>
 75             <li class="ts-ul-li2"><b></b></li>
 76             <li class="ts-ul-li3"><b></b></li>
 77             <li class="ts-ul-li4"><b></b></li>
 78         </ul>
 79     </div>
 80     <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
 81     <script type="text/javascript">
 82         $(function() {    
 83             var li_warp=$('.ts-ul')
 84             var totle=li_warp.children('li').length;
 85             var index=-1;
 86             var timeOut=null;    
 87             $(".ts-ul li").eq(0).addClass('on');
 88             $(".ts-ul li").hover(function(){
 89                 clearInterval(timeOut);
 90                 $(".ts-ul li").removeClass("on");
 91                 $(this).addClass("on");
 92                 index=$(this).index();
 93 //                console.log(index);
 94             },function(){
 95                 autoPlay();
 96             });
 97             function autoPlay(){
 98                 timeOut=setInterval(function(){
 99                     index++;                    
100                     $(".ts-ul li").eq(index).addClass('on').siblings('li').removeClass('on');
101                     if(index==totle){
102                         index=0;
103                     }                        
104                 },4000);
105             }
106             autoPlay();
107         });
108     </script>
109 </body>
110 
111 </html>

感觉每次写来写去都是差不多的,但是真正让自己动手还是有问题,归根到底还是练得太少啊,我都不好意思说自己是做了一年多的前端了呢-_-

转载于:https://www.cnblogs.com/U-can/p/5198900.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery手风琴图片轮播切换是一种常用的网页图片轮播效果,可以让网页内容更加生动,增强用户体验。手风琴效果是指在图片轮播时,当前图片会被放大,其他图片则会被压缩。以下是该效果的实现步骤: 1. HTML结构:创建一个包含所有图片的容器和一个包含所有小圆点的容器。 2. CSS样式:为容器和小圆点添加样式,设置图片的宽度、高度和位置。 3. JavaScript代码:实现图片轮播的逻辑。通过jQuery获取容器和小圆点,为小圆点添加点击事件,点击后切换到对应的图片,并给当前图片添加类名,其他图片则移除类名,实现手风琴效果。 以下是一个示例代码: HTML: ``` <div class="slider"> <div class="slider-wrapper"> <img src="img1.jpg" alt=""> <img src="img2.jpg" alt=""> <img src="img3.jpg" alt=""> </div> <div class="dots"> <span></span> <span></span> <span></span> </div> </div> ``` CSS: ``` .slider { width: 100%; height: 500px; position: relative; } .slider-wrapper { width: 100%; height: 100%; position: relative; } .slider-wrapper img { width: 100%; height: 100%; position: absolute; top: 0; left: 0; transition: all 0.5s ease-in-out; } .slider-wrapper img.active { transform: scale(1.2); } .dots { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); } .dots span { display: inline-block; width: 10px; height: 10px; margin-right: 10px; background-color: #ccc; border-radius: 50%; cursor: pointer; } .dots span.active { background-color: #f00; } ``` JavaScript: ``` $(function(){ var $slider = $('.slider'), $wrapper = $('.slider-wrapper'), $imgs = $('.slider-wrapper img'), $dots = $('.dots span'), len = $imgs.length, index = 0; // 初始化 $imgs.eq(0).addClass('active'); $dots.eq(0).addClass('active'); // 点击事件 $dots.on('click', function(){ var idx = $(this).index(); if(idx !== index){ $imgs.eq(index).removeClass('active'); $dots.eq(index).removeClass('active'); $imgs.eq(idx).addClass('active'); $dots.eq(idx).addClass('active'); index = idx; } }); }); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值