html图片实现左右滑动,jquery实现左右滑动式轮播图

本文实例为大家分享了jquery左右滑动轮播图的具体代码,供大家参考,具体内容如下

图片轮播jq(左右切换)

*{margin: 0;padding:0; }

ul{list-style: none;}

.banner{width: 600px;height: 300px;border: 2px solid #ccc;margin: 100px auto;position: relative;overflow: hidden;z-index: 1;}

.img{position: absolute;top: 0;left: 0;}

.des{position: absolute;bottom: 0;left: 0;z-index: -2;background: #ccc}

.des li{float: left;width: 600px;}

.img li{float: left;}

.num{position: absolute;bottom: 10px;width: 100%;text-align: center;font-size: 0;}

.num li{width: 10px;height: 10px;background:rgba(0,0,0,0.5);display: block;border-radius: 100%;display: inline-block;margin: 0 5px;cursor: pointer;}

.btn{display: none;}

.btn span{display: block;width: 50px;height: 100px;background: rgba(0,0,0,0.6);color: #fff;font-size: 40px;line-height: 100px;text-align: center;cursor:pointer;}

.btn .prev{position: absolute;left: 0;top: 50%;margin-top: -50px;}

.btn .next{position: absolute;right: 0;top: 50%;margin-top: -50px;}

.num .active{background-color: #fff;}

.hide{display: none;}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于 jQuery 的简单响应式轮播图的示例代码: HTML: ```html <div class="slider"> <div class="slides"> <div class="slide"><img src="img/slide1.jpg"></div> <div class="slide"><img src="img/slide2.jpg"></div> <div class="slide"><img src="img/slide3.jpg"></div> </div> <div class="controls"> <div class="prev"><i class="fa fa-chevron-left"></i></div> <div class="next"><i class="fa fa-chevron-right"></i></div> </div> </div> ``` CSS: ```css .slider { position: relative; width: 100%; max-width: 1200px; margin: 0 auto; } .slides { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; } .slide { scroll-snap-align: start; flex-shrink: 0; width: 100%; height: 500px; } .slide img { width: 100%; height: 100%; object-fit: cover; } .controls { position: absolute; top: 50%; transform: translateY(-50%); width: 100%; display: flex; justify-content: space-between; z-index: 1; } .prev, .next { cursor: pointer; padding: 20px; background-color: rgba(255, 255, 255, 0.8); border-radius: 50%; transition: background-color 0.5s; } .prev:hover, .next:hover { background-color: rgba(255, 255, 255, 1); } .prev { margin-left: 20px; } .next { margin-right: 20px; } ``` JavaScript: ```js $(function() { var slider = $(".slider"), slides = slider.find(".slides"), slide = slides.find(".slide"), prevBtn = slider.find(".prev"), nextBtn = slider.find(".next"), slideCount = slide.length, slideWidth = 100.0 / slideCount, slideIndex = 0; slide.each(function(index) { $(this).css({"left": (slideWidth * index) + "%"}); }); function showSlide(index) { slides.stop().animate({"left": (-100 * index) + "%"}, 500); slide.eq(index).addClass("active").siblings().removeClass("active"); } function nextSlide() { slideIndex++; if (slideIndex == slideCount) { slideIndex = 0; } showSlide(slideIndex); } function prevSlide() { slideIndex--; if (slideIndex < 0) { slideIndex = slideCount - 1; } showSlide(slideIndex); } prevBtn.on("click", prevSlide); nextBtn.on("click", nextSlide); $(window).resize(function() { slideWidth = 100.0 / slideCount; slide.each(function(index) { $(this).css({"left": (slideWidth * index) + "%"}); }); showSlide(slideIndex); }); }); ``` 这个轮播图会自动适应浏览器窗口大小,并且可以在移动设备上进行触摸滑动。你可以根据需要修改 CSS 样式和 JavaScript 代码来实现自己想要的效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值