桌面和移动设备的jQuery事件(jQuery events for both desktop and mobile)
我正在做一个完全响应的页面,并进入jQuery部分。 我的问题是如何做包括移动和桌面使用的事件。 我查看了jQuery 1.11.1文件,发现没有“触摸”的痕迹。 我想我可以用mousedown作为开始。 什么是最佳做法?
$('.touch-me').on('mousedown, click', function () { console.log('touch me'); });I'm doing a fully responsive page and got to the jQuery part. My question is how to do events that cover both mobile and desktop usage. I have looked in jQuery 1.11.1 file and found no trace of "touch". I figure that I could use mousedownas a start. What is best practice when it comes to this?
$('.touch-me').on('mousedown, click', function () { console.log('touch me'); });最满意答案
你可以使用touchstart:
$('.touch-me').on('mousedown touchstart', function () { console.log('touch me'); });PS:如果你也需要点击事件,那么使用它而不用逗号分隔它(只是你需要的空间)。
You can use touchstart:
$('.touch-me').on('mousedown touchstart', function () { console.log('touch me'); });PS: If you need click event too then use it without separating it with a comma (just a space you need).
更多推荐
jQuery,电脑培训,计算机培训,IT培训"/> <meta name="description" cont
发布评论