[英]“click” doesn't work on mobile
This is the javascript I use for my burger navigation. 这是我用于汉堡导航的JavaScript。 My code works perfectly on Chrome, but it doesn't works on my iPhone.
我的代码可以在Chrome上完美运行,但不能在我的iPhone上运行。 I think it has to do with the "click" but i'm not sure.
我认为这与“点击”有关,但我不确定。
I tried using "touchend" instead of click but that doesn't work either. 我尝试使用“ touchend”而不是单击,但这也不起作用。
This is my code: 这是我的代码:
onload = function() {
var hetMenu = document.querySelector("body > header nav");
hetMenu.addEventListener("click", menuToggle);
}
function menuToggle() {
var deBody = document.querySelector("body");
deBody.classList.toggle("navigatie");
console.log(deBody.classList);
}
Use both click and touchstart events. 同时使用click和touchstart事件。
See: onClick not working on mobile (touch) 请参阅: onClick无法在移动设备上运行(触摸)
It's jQuery but same events can be used. 它是jQuery,但可以使用相同的事件。
You can use 'touchstart' with jquery. 您可以在jQuery中使用“ touchstart”。
$('#button1').on('touchstart click', function(){ /* code here */ }); $('#button1')。on('touchstart click',function(){/ *代码在这里* /});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.