css实现移动端左右滑动效果

2018-10-14  本文已影响0人  明明明明如月

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

<script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>

<title>test</title>

<style>

body,

p {

margin: 0;

padding: 0;

}

.concent {

margin: 50px auto;

width: 100%;

max-width: 750px;

min-width: 320px;

}

.box {

white-space: nowrap;

overflow-x: auto;

}

/*注释1*/

.box::-webkit-scrollbar {

width: 0;

height: 0;

display: none;

}

/*注释2*/

.box div {

list-style: none;

display: inline-block;

width: 100px;

line-height: 30px;

margin-right: 10px;

background: #ccc;

text-align: center;

}

/*注释3*/

.box p {

width: 100%;

height: 50px;

background: pink;

}

.box div:last-child {

margin: 0;

}

</style>

</head>

<body>

<div class="concent">

<div class="box">

<!-- /*注释4*/ -->

<div>

<p></p><b>简简单单</b></div>

<div>

<p></p><b>简简单单</b></div>

<div>

<p></p><b>简简单单</b></div>

<div>

<p></p><b>简简单单</b></div>

<div>

<p></p><b>简简单单</b></div>

<div>

<p></p><b>简简单单</b></div>

</div>

</div>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script>

var u = navigator.userAgent;

var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端

var isUc = u.indexOf('UCBrowser') > -1; //uc浏览器

//var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

if(isAndroid && isUc) { /*注释5*/

$('.box').on('touchstart', function() {

$(document).on('touchmove', function(e) {

e.preventDefault();

});

$(document).on('touchend', function() {

$(document).unbind();

});

});

}

</script>

</body>

</html>

上一篇 下一篇

猜你喜欢

热点阅读