码迷,mamicode.com
首页 > 其他好文 > 详细

最新拖动原理

时间:2016-07-12 17:08:14      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>无标题文档</title>
</head>

<body>
<style type="text/css">
.oDiv{
    width:300px;
    height:200px;
    overflow:hidden;
    position:relative;
}
.oDiv ul{
  margin:0;
  padding:0;
  width:1200px;
  position:absolute;
  
}
.oDiv ul li{ 
    list-style:none;
    float:left;
    border-radius:4px;
    border:1px solid red;
    width:100px;
    height:50px;
}
</style>

<div class="oDiv">
    <ul id="oDiv">
        <li>你111</li>
        <li>你2222</li>
        <li>你333</li>
        <li>你444</li>
        <li>你555</li>
        <li>你666</li>
        <li>你777</li>
        <li>你888</li>
    </ul>
</div>

</body>

</html>

<script type="text/javascript" src="jquery.1.9.0.min.js"></script>
<script type="text/javascript">
$(function(){
     var x = 100;  
     var offsetX = 0;
     var dom= $("#oDiv");      
        dom.on("touchstart",function(event){
            var event = window.event;
            offsetX = event.touches[0].pageX-x;
            //console.log(event.touches[0].pageX+"-"+_this.x+"="+_this.offsetX);
        });
        dom.on("touchmove",function(event){
            var event = window.event;
            var tmpx=event.touches[0].pageX-offsetX;
            if(tmpx>=0 && tmpx< screenWidth-_this.width){}
            if(tmpx>5){
               tmpx=5;
            }else if(tmpx<-520){
                 tmpx=-520;
            }
            
            x = tmpx;
            dom.css({left:x});
            event.preventDefault();
            event.stopPropagation();
        });

})
     


</script>

 

最新拖动原理

标签:

原文地址:http://www.cnblogs.com/yjhua/p/5663880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!