简单的JQ横排响应式轮播图

HTML

<div class="box">
            <div class="pic">
                <ul class="clearfix">
                    <li><img src="img/952-440-1.jpg" alt="" /></li>
                    <li><img src="img/952-440-2.jpg" alt="" /></li>
                    <li><img src="img/952-440-3.jpg" alt="" /></li>
                    <li><img src="img/952-440-4.jpg" alt="" /></li>
                </ul>                                                               
            </div>
            <div class="tab">
                <a href="#" class="on">01</a>
                <a href="#">02</a>
                <a href="#">03</a>
                <a href="#">04</a>
            </div>
        </div>

CSS

*{margin:0;padding:0;}
            ul,li{list-style: none;display: block;}
            a{text-decoration:none; font-size:20px;color: #302833;}
            .clearfix:after{content: '';display: block;height: 0;visibility: hidden;clear: both;}
            .box{position: relative;width:100%; overflow: hidden;}
            .pic{position: absolute;left:0;width:400%;}         
            li{float:left;width:25%;}
            img{display: block;width: 100%;}
            .tab{width:50%;position: absolute;right:0;bottom:0;}
            .tab a{display: inline-block;width:20%;height:30px;line-height: 30px;background: red;color: #fff;text-align: center;}
            .on{background: blue !important;}

JS

$(function(){
            var $window_wid=$(window).width();
            $(".box").height($window_wid*0.46);  //盒子的高度始终是浏览器宽度的0.43
            $(window).resize(function(){
                 $window_wid=$(window).width();
                 $(".box").height($window_wid*0.46); 
//               console.log($(".box").height())
            });
            var box=$(".box"),  //  大盒子
            btns=box.find(">div.tab>a"),  //  获取a标签
            pic=box.find(".pic"),   // 找ul
            p=0;                 //  指示         
            btns.each(function(index,btn){
                btn=$(btn);  // 相当于 $(this)
                btn.mouseenter(function(){
                    if(index !=p){// 1 2 3
                        $(btns[p]).removeClass("on"); // 移出默认
                        btn.addClass("on");//  给当前 指示(a链接) 设置  
                        p=index;// 更新p 移除默认样式 
                        pic.stop().animate({
                            "left":-100*index+"%"
                        },300)
                    }
                })
            }).eq(0).mouseenter()

        })

效果

看两张图片的高度


这里写图片描述

这里写图片描述

好的,下面是横排四个响应式卡片的代码,并带有注释说明: ```html <div class="card-deck"> <!-- 使用 Bootstrap 提供的 card-deck 类,使卡片横向排列 --> <div class="card"> <img class="card-img-top" src="image1.jpg" alt="Card image cap"> <!-- 卡片顶部图片 --> <div class="card-body"> <h5 class="card-title">Card title</h5> <!-- 卡片标题 --> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> <!-- 卡片内容 --> <a href="#" class="btn btn-primary">Go somewhere</a> <!-- 按钮链接 --> </div> </div> <div class="card"> <img class="card-img-top" src="image2.jpg" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Card title</h5> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div> <div class="card"> <img class="card-img-top" src="image3.jpg" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Card title</h5> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div> <div class="card"> <img class="card-img-top" src="image4.jpg" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Card title</h5> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div> </div> ``` 这里使用了 Bootstrap 中提供的 `card` 和 `card-deck` 类,实现了横排四个响应式卡片。其中,`card` 类用来定义卡片的基本样式,包括边框、圆角等;`card-deck` 类用来将多个卡片横向排列,并保证它们在不同屏幕宽度下的自适应布局。每个卡片内部包含了图片、标题、内容和按钮等元素,用来展示不同的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值