admin管理员组文章数量:1277895
First of all, I know this has been answered a lot of times, but all the things I try to do, they're not working. So here's my problem:
I have a non-displayed div that I want to show when the users clicks a div, so I have this javascript code:
$(document).ready(function() {
$(".hamburger-menu").on("click", function(){
var display = $(".menu-mobile").css("display");
if (display == "none") {
$(".menu-mobile").css("display", "block");
} else {
$(".menu-mobile").css("display", "none");
}
});
});
This works perfectly on my desktop but doesn't work in my mobile.
What I found in the other answers was to change the .on("click") value to .on("click touchstart") or .on("tap"), but they both don't work.
So what's the problem? I have another animation that doesn't require any click event and it works perfectly and smoothly on my mobile. Could anyone help me?
Thanks.
First of all, I know this has been answered a lot of times, but all the things I try to do, they're not working. So here's my problem:
I have a non-displayed div that I want to show when the users clicks a div, so I have this javascript code:
$(document).ready(function() {
$(".hamburger-menu").on("click", function(){
var display = $(".menu-mobile").css("display");
if (display == "none") {
$(".menu-mobile").css("display", "block");
} else {
$(".menu-mobile").css("display", "none");
}
});
});
This works perfectly on my desktop but doesn't work in my mobile.
What I found in the other answers was to change the .on("click") value to .on("click touchstart") or .on("tap"), but they both don't work.
So what's the problem? I have another animation that doesn't require any click event and it works perfectly and smoothly on my mobile. Could anyone help me?
Thanks.
Share Improve this question edited Nov 16, 2014 at 19:59 Omar 31.7k9 gold badges72 silver badges116 bronze badges asked Nov 16, 2014 at 19:30 peregraumperegraum 5371 gold badge8 silver badges19 bronze badges 4-
2
One suggestion, instead of
$(document).ready(function() { $(".hamburger-menu").on("click", function(){ var display = $(".menu-mobile").css("display"); if (display == "none") { $(".menu-mobile").css("display", "block"); } else { $(".menu-mobile").css("display", "none"); } }); });
could you not do$(".hamburger-menu").on("click", function(){ $(".menu-mobile").toggle();
– Billy Commented Nov 16, 2014 at 19:37 - @Billy Oh, yes! Sorry, I'm not really into javascript so I didn't really know this function existed.... Hahahahaha thanks! ;) – peregraum Commented Nov 16, 2014 at 19:45
- Sorry I couldn't help with the actual problem, Don't know too much about web designing for mobile, Good luck though.. – Billy Commented Nov 16, 2014 at 19:54
- @Billy Don't worry! Thanks for the advice though! – peregraum Commented Nov 16, 2014 at 20:00
1 Answer
Reset to default 6there are some issues with jquery and detecting touches. i find it best to set event listeners with javascript for this sort of thing. I've had luck with something like this:
this.addEventListener('touchend', function(e){happens(e)}, false);
touchend
is a good mouseup
equivalent for mobile. touchstart
should work for mousedown
like you were trying.
本文标签: javascriptOn click event for mobileStack Overflow
版权声明:本文标题:javascript - On click event for mobile? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741255376a2366570.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论