jQuery 鼠标滑动切换图片 手风琴

2 篇文章 0 订阅

jQuery 鼠标滑动切换图片 手风琴

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>手风琴</title>
    <script src="./jQuery.js"></script>
    <style>
        .bigbox{
            width: 610px;
            height: 270px;
            border: 1px solid #ccc;
            margin: 0 auto;
        }
        ul{
            margin: 0;
            padding: 0;
            float: left;
            height: 270px;
        }
       li{
            float: left;
            list-style: none;
            width: 50px;
            height: 270px;
            border: 1px solid #ccc;
            overflow: hidden;
        }
        img{
            width: 400px;
        }
        .ww{
            width: 400px;
        }
    </style>
</head>
<body>
    <div class="bigbox">
        <ul class="q">
            <li class="ww"><img src="./image/d1.jpeg" alt=""></li>
            <li><img src="./image/d2.jpeg" alt=""></li>
            <li><img src="./image/d3.jpeg" alt=""></li>
            <li><img src="./image/d4.jpeg" alt=""></li>
            <li><img src="./image/d5.jpeg" alt=""></li>
        </ul>
    </div>
    <script>
        $(function(){
            $('.q li').mouseover(function(){
                $('.q li').removeClass();
                $(this).addClass('ww');
            })
        })
    </script>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery手风琴是一种常见的网页元素,它可以通过鼠标移入事件来实现图片轮播切换效果。实现方法如下: 1. 在HTML中创建手风琴元素,并在其中添加图片和文字等内容。 2. 使用CSS将手风琴元素排列在一行或一列上,并设置每个元素的宽度和高度,以及背景色等样式。 3. 使用jQuery鼠标移入事件中,获取当前手风琴元素的位置和宽度,以及其他元素的位置和宽度等信息。 4. 根据当前鼠标所在的位置,计算出需要展开或收缩的手风琴元素的宽度和位置,并使用jQuery的animate()方法实现动画效果。 以下是一个简单的示例代码: HTML代码: ``` <div class="accordion"> <div class="item"> <img src="image1.jpg"> <p>描述1</p> </div> <div class="item"> <img src="image2.jpg"> <p>描述2</p> </div> <div class="item"> <img src="image3.jpg"> <p>描述3</p> </div> </div> ``` CSS代码: ``` .accordion { display: flex; flex-direction: row; justify-content: space-between; align-items: center; width: 100%; } .item { width: 30%; height: 200px; background-color: #ccc; overflow: hidden; position: relative; } .item img { width: 100%; height: auto; } .item p { position: absolute; bottom: 0; left: 0; width: 100%; margin: 0; padding: 10px; background-color: rgba(0,0,0,0.5); color: #fff; } ``` JavaScript代码: ``` $('.item').mouseenter(function() { var currentIndex = $(this).index(); var itemWidth = $(this).width(); var itemLeft = $(this).offset().left; var totalWidth = $('.accordion').width(); var spaceWidth = (totalWidth - itemWidth * $('.item').length) / ($('.item').length - 1); $('.item').each(function(index) { if (index != currentIndex) { var left = spaceWidth * index + itemWidth * index; if (index < currentIndex) { left -= (currentIndex - index) * spaceWidth; } else { left += (index - currentIndex) * spaceWidth; } $(this).animate({ 'left': left }, 500); } }); $(this).animate({ 'width': totalWidth - itemWidth * ($('.item').length - 1) }, 500); }).mouseleave(function() { $('.item').each(function(index) { var left = spaceWidth * index; $(this).animate({ 'left': left }, 500); }); $(this).animate({ 'width': itemWidth }, 500); }); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值