jQuery - 手风琴效果 -

本文介绍了一种使用HTML、CSS及jQuery实现的图片滑动轮播效果。当鼠标悬停于不同图片时,其余图片会自动调整位置,确保当前图片处于可视区域中央。鼠标移开后,所有图片恢复原始状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            padding:0;
            margin:0;
        }
        ul,ol{
            list-style: none;
        }
        .box{
            width: 900px;
            height: 300px;
            border:1px solid #333;
            margin:50px auto;
            position: relative;
            overflow: hidden;
        }
        .box ul li{
            position: absolute;
            width: 560px;
            height: 300px;
            top:0px;
        }
        .box ul li.no0{
            left:0px;
        }
        .box ul li.no1{
            left:180px;
        }
        .box ul li.no2{
            left:360px;
        }
        .box ul li.no3{
            left:540px;
        }
        .box ul li.no4{
            left:720px;
        }
    </style>
</head>
<body>
    <div class="box" id="box">
        <ul>
            <li class="no0"><a href=""><img src="images/0.jpg" alt=""></a></li>
            <li class="no1"><a href=""><img src="images/1.jpg" alt=""></a></li>
            <li class="no2"><a href=""><img src="images/2.jpg" alt=""></a></li>
            <li class="no3"><a href=""><img src="images/3.jpg" alt=""></a></li>
            <li class="no4"><a href=""><img src="images/4.jpg" alt=""></a></li>
        </ul>
    </div>
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript">
        $(".no0").mouseenter(function(){
            // 防流氓
            $("li").stop(true);
            $(".no1").animate({"left":560},500);
            $(".no2").animate({"left":560 + 85},500);
            $(".no3").animate({"left":560 + 85 * 2},500);
            $(".no4").animate({"left":560 + 85 * 3},500);
        });

        $(".no1").mouseenter(function(){
            // 防流氓
            $("li").stop(true);
            $(".no1").animate({"left":85},500);
            $(".no2").animate({"left":560 + 85},500);
            $(".no3").animate({"left":560 + 85 * 2},500);
            $(".no4").animate({"left":560 + 85 * 3},500);
        });

        $(".no2").mouseenter(function(){
            // 防流氓
            $("li").stop(true);
            $(".no1").animate({"left":85},500);
            $(".no2").animate({"left":85 * 2},500);
            $(".no3").animate({"left":560 + 85 * 2},500);
            $(".no4").animate({"left":560 + 85 * 3},500);
        });

        $(".no3").mouseenter(function(){
            // 防流氓
            $("li").stop(true);
            $(".no1").animate({"left":85},500);
            $(".no2").animate({"left":85 * 2},500);
            $(".no3").animate({"left":85 * 3},500);
            $(".no4").animate({"left":560 + 85 * 3},500);
        });

        $(".no4").mouseenter(function(){
            // 防流氓
            $("li").stop(true);
            $(".no1").animate({"left":85},500);
            $(".no2").animate({"left":85 * 2},500);
            $(".no3").animate({"left":85 * 3},500);
            $(".no4").animate({"left":85 * 4},500);
        });

        // 鼠标离开大盒子,所有的li恢复原状。
        $("#box").mouseleave(function(){
            $("li").stop(true);
            $(".no1").animate({"left":180},300);
            $(".no2").animate({"left":360},300);
            $(".no3").animate({"left":540},300);
            $(".no4").animate({"left":720},300);
        });
    </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值