html5移动端拖拽

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html5移动端拖拽相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1.0" name="viewport"/>
<title>论坛列表</title>
<link href="css/Style.css" rel="stylesheet" />
</head>
<body style="background:#f8f8f8;">
<div class="p-bbs-list">
<ul>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list1.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list2.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list3.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list4.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list4.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list4.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
<li>
<div class="p-bbs-list-left"><img src="img/bbs-list4.png"></div>
<div class="p-bbs-list-right">
<p><a href="kk_luntanNR.html">XXX产品4月上线你关注了嘛?</a></p>
<div class="bbs-bm">
<div class="bbs-li-bm">
<img src="img/bbs-st.png"><span>Stvetn</span>
<img src="img/bbs-xiaoxi.png"><span>20</span>
</div>
<div class="bbs-li-bm2">
<img src="img/bbs-time.png"><span>2016-3-29</span>
</div>
</div>
</div>
</li>
</ul>
<div class="bbs_sign" id="bbsSi" draggable="true"><img src="img/bi.png">我要发帖</div>
</div>
<script type="text/javascript">
var bbsSi=document.getElementById("bbsSi");
//监听
bbsSi.addEventListener(‘touchmove‘,function(event){
//阻止默认
event.preventDefault();
//判断是否是一个手指
if(event.targetTouches.length==1)
{
//拖拽最后的位置
var touch = event.targetTouches[0];
bbsSi.style.right = 0;
bbsSi.style.top = touch.pageY + ‘px‘;    }
},false);
</script>
</body>
</html>

 

以上是关于html5移动端拖拽的主要内容,如果未能解决你的问题,请参考以下文章

关于移动端拖拽

移动端拖拽(模块化开发,触摸事件,webpack)

pc端移动端拖拽实现

Sortable.js移动端拖拽排序的容器li标签里含有其他点击事件如何写

React之卡片拖拽移动

pc端拖拽事件