使图片列表在左右两端滚动。
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>