|
对啊,用longpress监听,但是好像拿不到长按的对象?你上面的代码我试过了,好像也不行啊<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<title>title</title>
<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
</head>
<body>
<div class="aui-content aui-margin-b-15">
<div>
<h1>按我</h1></div>
</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
apiready = function() {
api.addEventListener({
name: 'longpress'
}, function(ret, err) {
console.log(JSON.stringify(ret));
console.log(JSON.stringify(err));
alert('长按了页面');
});
}
var time;
function getTimeNow() {
var now = new Date();
return now.getTime();
}
function touchend() {
clearInterval(time); //如果按下时间不到1000毫秒便弹起,
}
function touchstart(obj) {
timeStart = getTimeNow(); //获取鼠标按下时的时间
time = setInterval(function() {
timeEnd = getTimeNow(); //也就是每100毫秒获取一次时间
if (timeEnd - timeStart > 700) //如果此时检测到的时间与第一次获取的时间差有1000毫秒
{
clearInterval(time); //便不再继续重复此函数 (clearInterval取消周期性执行)
if ($api.attr($api.last(obj), 'style')) {
$api.removeAttr($api.last(obj), 'style');
}
}
}, 100);
alert(obj.innerHtml)
}
</script>
</html>
|
|