jQuery之焦点图转换

之前写过一个超级简单的焦点图,现在换一种思路开始添加一些新东西。

新思路:让盒子动(所以首先布局要清晰。给四张图套两个盒子,里层盒子大小等于四张图片横向排布,外层盒子等于一张图片的大小,并overflow:hidden。这样就可以只显示我们看到的一张图,并且用动画实现图片来回转换)。a标签href不写图片路径。a标签之间不加数字,通过索引值index()来找到。

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>焦点图转换</title>
    <link rel="stylesheet" href="css/reset.css">
    <style type="text/css">
        .pic-show{width: 480px;overflow: hidden;}
        .pic{width: 1920px;height: 320px;position: relative;}
        img{display: block;float: left;}
        ul{width: 120px;height: 18px;position: absolute;top: 280px;left: 185px;}
        li{float: left;width: 20px;height: 18px;margin-left: 5px;}
        a{display: block;width: 20px;height: 18px;text-decoration: none;border: 1px solid #ccc;border-radius: 50%;background-color: #ccc;opacity: 0.6;}
        .aHover{background-color: #3b216a;} 
        .aCss{background-color: #094a99;}
    </style>
</head>
<body>
    <div class="pic-show">
        <div class="pic">
            <img src="images/1.jpg" alt="">
            <img src="images/2.jpg" alt="">
            <img src="images/3.jpg" alt="">
            <img src="images/4.jpg" alt="">
        </div>
        <ul>
            <li><a class="aCss" href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
        </ul>
    </div>
    <script src="js/jquery-3.0.0.js"></script>
    <script type="text/javascript">
        $("ul li a").click(function(event){
            var num=$(this).parent().index();//获取索引值
            var mlNum=num * -480+'px';//字符串链接
            //$(".pic").css("margin-left",mlNum)
            $(".pic").animate({"margin-left":mlNum},500)//动画
            //$(this).css("background-color","#494a93").parent().siblings().find("a").css("background-color","#ccc");//链式操作 
            $(this).addClass("aCss").parent().siblings().find("a").removeClass("aCss");//addClass 
            event.preventDefault();
        })
        $("ul li a").hover(function(){
            $(this).addClass("aHover")
        },function(){
            $(this).removeClass("aHover")
        })
    </script>
</body>
</html>

 

转载于:https://www.cnblogs.com/ljm-fight/p/6160580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值