swiperLeft/swiperRight以及js长按事件

来源:互联网 发布:开源的数据库审核平台 编辑:程序博客网 时间:2024/04/29 21:55

<script src="../../style/js/jquery.min.js"></script>
<script src="../../style/expand/jquery.event.move.js"></script>
<script src="../../style/expand/jquery.event.swipe.js"></script>
<style type="text/css">
.list-container{min-height:0rem;overflow:hidden;margin-top:10rem;background:#fff;}
.list-container > li{background: #ffffff;margin-bottom:2px;display:block;overflow: hidden;height:9rem;line-height:9rem;border-top: 0.2rem solid #d8d8d8;font-size:3rem;}
.list-container> li a{position: relative;height:9rem;display: inline-block;width: 100%;float: left;}
.logText{text-indent:3rem;width:70%;display:inline-block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.logTime{padding-right:3rem;display:inline-block;float:right;}
.list-container li > span{display:inline-block;width:150px;background:red;height:9rem;text-align:center;line-height:9rem;}
</style>
</head>
<body>
<ul class="list-container">
  <li id="2007">
   <a href="#"><span class="logText">哈哈是啊撒是打发啊发撒地方阿斯顿发生的发撒地方阿斯顿发生的发撒地方暗示法打速度发V阿斯顿发撒话</span><span class="logTime">2014-6-12</span></a>
  <span class="logDel" onclick="del(this)">删除</span>
 </li>
</ul>
</body>
</html>
<script>
function swiperLi(){
      var cont=$(".list-container li");
      cont.on('swipeleft', function(e) {$(this).find("a").css("margin-left",-150);});
      cont.on('swiperight', function(e){$(this).find("a").css("margin-left",0);});
}
swiperLi();
</script>

手机端js模拟长按事件(代码仿照jQuery)

代码编写:

1
2
3
4
5
6
7
8
9
10
11
12
$.fn.longPress = function(fn) {
    var timeout = undefined;
    var $this this;
    for(var i = 0;i<$this.length;i++){
        $this[i].addEventListener('touchstart'function(event) {
            timeout = setTimeout(fn, 800);
            }, false);
        $this[i].addEventListener('touchend'function(event) {
            clearTimeout(timeout);
            }, false);
    }
}

代码使用:

1
2
3
$(select).longPress(function(){
    alert(1);
});
0 0
原创粉丝点击