jquery 实现图片列表在两端来回滚动

使图片列表在左右两端滚动。

css代码:
.d_item{
			display: flex;
			margin: 0 15px;
		}
html代码:
<div id="demo" style="overflow: hidden; width: 500px;margin: 0 auto;">
		<div id="demo1" style="display: flex;">
			<div class="d_item">
			    <a href="#" target="_blank">
			        <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F210F2130512J47-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662101199&t=7c5549bfc4cc8fd093523fd299a91ea3" width="150" alt="第一张图" height="100"></a>
			</div>
			<div class="d_item">
			    <a href="#" target="_blank">
			        <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.redocn.com%2Fsheying%2F20150507%2Fpugongying_4267498.jpg&refer=http%3A%2F%2Fimg.redocn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662101199&t=24ff1fa638ec571d090142ea49076ef6" width="150" alt="第二张图" height="100"></a>
			</div>
			<div class="d_item">
			    <a href="#" target="_blank">
			        <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp06%2F20111116192A364-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662101199&t=9b7b99bbee5ac6726dc7815db0784805" width="150" alt="第三张图" height="100"></a>
			</div>
			<div class="d_item">
			    <a href="#" target="_blank">
			        <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.redocn.com%2Fsheying%2F20150507%2Fpugongying_4267498.jpg&refer=http%3A%2F%2Fimg.redocn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662101199&t=24ff1fa638ec571d090142ea49076ef6" width="150" alt="第四张图" height="100"></a>
			</div>
			<div class="d_item">
			    <a href="#" target="_blank">
			    <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp06%2F20111116192A364-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662101199&t=9b7b99bbee5ac6726dc7815db0784805s" width="150" alt="第五张图" height="100"></a>
			</div>
		</div>
	    </div>
js代码:
<script type="text/javascript">
	  $(function(){
		  //两端之间来回滚动
		  let speed=30;
		 let offset = 0;
		 let rollList = true;
		  function Marquee(){
		      if(rollList){
		      	offset += -1;
		      }else{
		      	offset += 1;
		      }
		      if(offset <= -410){
		      	rollList = false;
		      }
		      if(offset == 0){
		      	rollList = true;
		      }
		      $("#demo1").css({
		      	marginLeft:offset
		      })
		  }
		  var roll=setInterval(Marquee,speed)
		  $("#demo1").mouseover(function() {
		      clearInterval(roll);
		  } )
		  $("#demo1").mouseout(function() {
		      roll=setInterval(Marquee,speed);
		  } )
	  })
      
      </script>
效果图:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值