jQuery 实现点击向右滚动

这个示例展示了一个HTML结构,其中包含六个使用不同SVG背景图的div元素,这些元素构成了一个横向滚动条。CSS定义了每个元素的样式,包括宽度、高度、边框圆角和背景图片。jQuery代码实现了点击‘下一页’按钮时,滚动内容的功能,通过调整margin-left实现平滑滚动。此功能适用于前端界面的导航或展示模块。

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

1. html
<div class="item" style="display: flex">
    <div class="item-body" id="item-body">
      <div class="item-body-c item-body-c1" onclick="openIframe('zdgz')">
      </div>
      <div class="item-body-c item-body-c2" onclick="openIframe('jhzj')">
      </div>
      <div class="item-body-c item-body-c3" onclick="openIframe('bmdt')">
      </div>
      <div class="item-body-c item-body-c4" onclick="openIframe('zyhy')">
      </div>
      <div class="item-body-c item-body-c5" onclick="openIframe('ndbg')">
      </div>
      <div class="item-body-c item-body-c6" onclick="openIframe('yyjc')">
      </div>
    </div>
    <div style="line-height: 16vh;height: 16vh;margin-right: 5vw;display: none;" class="nextCss">
      <img class="next" src="${rc.contextPath}/static/image/home/Vector 39.png" />
    </div>
  </div>
2. css
.item-body-c {
      float: left;
      width: 168px;
      height: 122px;
      background-size: 100% 100%;
      background-repeat: no-repeat;
      border-radius: 10px;
      margin: 10px;
    }

    .item-body-c1 {
      background-image: url("${rc.contextPath}/static/image/home/Group 180.svg");
    }

    .item-body-c2 {
      background-image: url("${rc.contextPath}/static/image/home/Group 181.svg");
    }

    .item-body-c3 {
      background-image: url("${rc.contextPath}/static/image/home/Group 182.svg");
    }

    .item-body-c4 {
      background-image: url("${rc.contextPath}/static/image/home/Group 183.svg");
    }

    .item-body-c5 {
      background-image: url("${rc.contextPath}/static/image/home/Group 184.svg");
    }

    .item-body-c6 {
      background-image: url("${rc.contextPath}/static/image/home/Group 185.svg");
    }

    .item-body {
      width: 2000%;
      height: 16vh;
      overflow: hidden;
    }
3. jQuery
$(".next").click(function () {
  index++;
  var lis = $("#item-body .item-body-c").length;
  if (index + 8 > lis) {
    $("#item-body").stop().append($("#item-body").html());
  }
  // 188是图片的width + padding + margin以后的值
  $("#item-body").stop().animate({ marginLeft: -index * 188 }, 1000);
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值