最近在做到移动端的网页
有多张图片,怕性能影响不敢使用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;
然后就可以愉快得滑动了
复制上面代码,在谷歌浏览器里打开模拟手机浏览器的功能,就可以滑动了