移动端多图片滑动

最近在做到移动端的网页

有多张图片,怕性能影响不敢使用JS轮播

最后利用了overflow的scroll 横行滚动条来实现滑动

<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Document</title>
</head>
<body>
	 <style type="text/css">
	 	body{
	 		width: 100%;
	 		font-size: 0px;
	 	}
	 	*{
	 		margin: 0;
	 		padding: 0;
	 	}
        #test{
        height: 200px;
        overflow-x: auto;
        overflow-y: hidden;
        font-size: 0px;
        white-space: nowrap;
        }
        .itemi{
            height: 200px;
            display: inline-block;
            border: none;

        }
        </style>
        <div id="test">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/d5/1407558376_e0b1f.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/cc/1407558376_05244.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/81/1407558376_fd53b.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/58/1407558376_db052.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/81/1407558376_fd53b.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/58/1407558376_db052.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/81/1407558376_fd53b.JPG">
            <img class="itemi" src="http://market.scau.edu.cn/files/upload/photos/201408/58/1407558376_db052.JPG">
        </div>
</body>
</html>
关键代码是

        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
然后就可以愉快得滑动了

复制上面代码,在谷歌浏览器里打开模拟手机浏览器的功能,就可以滑动了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值