如何模拟手机浏览器的触摸事件?安卓、iPhone?
我正在创建一个网络应用程序。我在移动浏览器上测试它并注意到 :active 伪类 dsnt 确实有效。我应该如何模拟移动浏览器的点击?我正在使用 CSS 精灵。我偶然发现了 ontouchstart 但不知道如何使用它。谁能帮我解决这个问题吗?提前致谢。
I am creating a web app. I was testing it on a mobile browser and noticed that :active pseudo class dsnt really work. How should I simulate clicks for mobile browser? I am using css sprites. I stumbled upon ontouchstart but dont know how to use that. can anyone help me over it? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完全正确,
ontouchstart
将帮助您实现一些目标,从更改 CSS 到能够在支持触摸事件的触摸设备上拖动元素。您正在使用 jQuery,它允许您将这些事件绑定到您的元素。我写了一篇关于 PHPAlchemist 的 文章.com 详细介绍了为移动设备创建具有触摸事件集成的自定义滚动条的必要步骤,但这可能有点影响深远。本质上,你会想要做这样的事情(jQuery Javascript 代码):
...然后,在你的 CSS 中,你可以有这样的事情,例如:
简而言之,你在触摸开始时向按钮添加一个类,并在触摸结束时将其删除,CSS 将控制它的外观。希望这有帮助! :)
Quite right, the
ontouchstart
will help you achieve something, from changing CSS to being able to drag elements on touch devices supporting the touch events. And you're using jQuery, which will allow you to bind those events to your elements.I wrote an article on PHPAlchemist.com detailing the necessary steps to creating a custom scrollbar with touch event integration for mobile devices, but that might be a bit far-reaching. Essentially, you would want to do something like this (jQuery Javascript code):
...then, in your CSS, you could have something like this for example:
In a nutshell, you're adding a class to your button on touch start, and removing it when the touch ends, and the CSS will control what it looks like. Hope this helps! :)