[英]Hiding <div> block doesn't work on mobile
I have callback button and hidden callback form. 我有回调按钮和隐藏的回调形式。 Form shows up after click on button and hide after click on any place on the screen except the form-space. 单击按钮后显示表单,单击屏幕上除表单空间以外的任何位置后隐藏。 BUT! 但! Form don't hide on mobile devices. 表单不会隐藏在移动设备上。 I think that problem is in touch tracking on iOS. 我认为问题在于iOS上的触摸跟踪。 How can i fix this problem? 我该如何解决这个问题?
function showcallbackform (objName) { if ( $(objName).css('display') == 'none' ) { $(objName).animate({height: 'show'}, 200); } else { $(objName).animate({height: 'hide'}, 200); } }; jQuery(function($){ $(document).mouseup(function (e){ var div = $("#callback-form"); if (!div.is(e.target) && div.has(e.target).length === 0) { div.hide(); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You can bind both actions (mouse and touch events) like this: 您可以像这样绑定两个动作(鼠标和触摸事件):
jQuery(function($){
$(document).bind( "mouseup touchend", function(e){
var div = $("#callback-form");
if (!div.is(e.target)
&& div.has(e.target).length === 0) {
div.hide();
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.