与iPad/iPhone兼容的Mousedown事件? -jQuery Mobile [英] Mousedown Event with ipad/iphone Compatibility? - jQuery Mobile
问题描述
我在jquery中写了一个小滚动条.滚动条似乎可以在PC和Mac上完美运行.但是,它在触摸设备上不起作用.
I wrote a small scroller in jquery. The scroller seems to work perfectly on PC and Macs. However it doesn't work on touch devices.
我想这是由于调用了mousedown
属性.如何在PC和触摸屏设备上都可以使用此功能?
I guess this is due to mousedown
property being called. how do I make this work on both PC and touch screen devices?
谢谢
$('.scroll-nav-up, .scroll-nav-down').live('click', function(){
$('.scroller-wrap').stop();
return false;
});
$('.scroll-nav-up').live('mousedown', function(){
$(this).closest('.item').find('.scroller-wrap').animate({
top: -($(this).closest('.item').find('.scroller-wrap').height() - 250)
}, 800);
});
$('.scroll-nav-down').live('mousedown', function(){
$(this).closest('.item').find('.scroller-wrap').animate({
top: 0
}, 800);
});
推荐答案
没有发现特别之处,因此目前我正在使用2个脚本.第一个脚本标识了Alastair Campbell在检测触摸-基于浏览.
Nothing special found, so at this moment I am using 2 scripts. The first script identifies the the touch screen devices as written by Alastair Campbell on Detecting touch-based browsing.
function isTouchDevice() {
var el = document.createElement('div');
el.setAttribute('ongesturestart', 'return;');
if(typeof el.ongesturestart == "function"){
return true;
}else {
return false
}
}
,然后将mousedown
事件用于常规浏览器,并将tap
事件用于触摸屏设备.
and then use the mousedown
event for regular browsers and use tap
event for touch screen devices.
P.S-同时使用jQuery和jQuery Mobile
P.S - Using both jQuery and jQuery Mobile
这篇关于与iPad/iPhone兼容的Mousedown事件? -jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!