我与Twitter的引导工作,并冲进一些iPad和iPhone上测试时我无法修复。 在移动(至少那些设备),你需要点击搞尖端或酥料饼(如预期)。 问题是,你永远无法将其关闭,一旦你做的。 我添加了一个监听器来关闭它,如果你再次点击它,但我觉得很难相信,默认行为不会点击将其删除。 这是在引导酥料饼和工具提示错误? 我的代码如下 - 它似乎工作,但只有当你点击创建尖端或酥料饼相同的项目 - 在任何地方的网页上(无法得到那个工作)。
代码火灾:
$(function () {
//Remove the title bar (adjust the template)
$(".Example").popover({
offset: 10,
animate: false,
html: true,
placement: 'top',
template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><div class="popover-content"><p></p></div></div></div>'
//<h3 class="popover-title"></h3>
//Need to have this click check since the tooltip will not close on mobile
}).click(function(e) {
jQuery(document).one("click", function() {
$('.Example').popover('hide')
});
});
});
HTML:
<a href="javascript:void(0);" class="Example" rel="popover" data-content="This is the Data Content" data-original-title="This is the title (hidden in this example)">
提前致谢!
丹尼斯
Answer 1:
我试图数十张贴StackOverflow的解决方案和网络的其他各个角落的,下面仅仅是对我工作的一个!
说明
如前所述在这里 ,你可以为了一个CSS-指令的元素,使其触摸设备点击。 我不能告诉你为什么工程或正在发生的事情有,但似乎是这样。 所以,我想使又名整个文档body
在移动设备上,这将让我随时随地触摸驳回酥料饼的点击。
酥料饼的JS
$(function () {
$('[data-toggle="popover"]').popover({ trigger: "hover"}})
});
路线
1.安装的Modernizr
我使用的轨道,所以我用了宝石 。
gem 'modernizr-rails'
2.创建一个touch
与CSS-指令级
以下添加到您的CSS:
.touch {
cursor: pointer
}
3.在触摸设备而已,添加touch
类的body
如果你想等元素,可以点击,而不是整个body
中,添加touch
类给他们。
if (Modernizr.touch) {
$( "body" ).addClass( "touch" );
}
而已! 现在,你可以在桌面上(甚至悬停触发)正常使用酥料饼,这将是触摸可取消移动。
Answer 2:
我有同样的问题,我的iPad。 但是,在浏览器正常工作。 解决方法对我来说是增加听众对所有可能的元素,我可以隐藏工具提示:
$('*').bind('touchend', function(e){
if ($(e.target).attr('rel') !== 'tooltip' && ($('div.tooltip.in').length > 0)){
$('[rel=tooltip]').mouseleave();
e.stopPropagation();
} else {
$(e.target).mouseenter();
}
});
是的,小的开销,为所有的提示发送事件,但不能定义哪些元素工具提示显示。
Answer 3:
请参考下面的代码来获得它的工作原理:
$('[data-toggle="popover"]').popover();
$('body').on('click', function (e) {
$('[data-toggle="popover"]').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
这是对身体检测点击和关闭页上的所有工具提示的最简单的方法。
您可以检查活生生的例子在这里
Answer 4:
主要概念是手动使酥料饼上的移动设备
$(document).ready(function() {
if ('ontouchstart' in window) {
$('[data-toggle="popover"]').popover({
'trigger': 'manual'
});
}
});
Answer 5:
Bootstap-提示v3.3.7
实际:悬停提示不能在我们的项目中使用触摸设备工作
解决方案:订阅工具提示的表演活动和呼叫的mouseenter
$body = $('body');
$body.tooltip({selector: '.js-tooltip'});
// fix for touch device.
if (Modernizr.touch) { // to detect you can use https://modernizr.com
var hideTooltip = function(e) {
tooltipClicked = !!$(e.target).closest('.tooltip').length;
if (tooltipClicked) { return; }
$('.js-tooltip').tooltip('hide');
}
var emulateClickOnTooltip = function(e) {
tooltipsVisible = !!$('.tooltip.in').length;
if (tooltipsVisible) { return; }
$(e.target).mouseenter();
}
var onTooltipShow = function(e) {
tooltipClicked = !!$(e.target).closest('.tooltip').length;
if (tooltipClicked) { return; }
$body.on('touchend', hideTooltip);
}
var onTooltipHide = function() {
$body.off('touchend', hideTooltip);
}
$body
.on('touchend', '.js-tooltip', emulateClickOnTooltip)
.on('show.bs.tooltip', onTooltipShow)
.on('hide.bs.tooltip', onTooltipHide);
}
Answer 6:
解决这个的jsfiddle ,测试在iOS(iPad和iPhone),Android和Windows。
$(document).ready(function(){
var toolOptions;
var toolOptions2;
var isOS = /iPad|iPhone|iPod/.test(navigator.platform);
var isAndroid = /(android)/i.test(navigator.userAgent);
///////////////////////////////////////// if OS
if (isOS){
toolOptions = {
animation: false,
placement:"bottom",
container:"body"
};
$('.customtooltip').tooltip(toolOptions);
$('.customtooltip').css( 'cursor', 'pointer' );
$('body').on("touchstart", function(e){
$(".customtooltip").each(function () {
// hide any open tooltips when the anywhere else in the body is clicked
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.tooltip').has(e.target).length === 0) {
$(this).tooltip('hide');
}////end if
});
});
///////////////////////////////////////// if Android
} else if(isAndroid){
toolOptions = {
animation: false,
placement:"bottom",
container:"body"
};
toolOptions2 = {
animation: false,
placement:"left",
container:"body"
};
$('.c_tool1').tooltip(toolOptions);
$('.c_tool2').tooltip(toolOptions);
$('.c_tool3').tooltip(toolOptions2);
///////////////////////////////////////// if another system
} else {
toolOptions = {
animation: true,
placement:"bottom",
container:"body"
};
$('.customtooltip').tooltip(toolOptions);
}//end if system
document.getElementById("demo").innerHTML = "Sys: "+navigator.platform+" - isOS: "+isOS+" - isAndroid: "+isAndroid;
});
<h6>
first <a href="#!" title="" class="customtooltip c_tool1" data-original-title="data del toolltip numero 1">tooltip</a>
Second <a href="#!" title="" class="customtooltip c_tool2" data-original-title="data del toolltip numero 2">tooltip</a>
third <a href="#!" title="" class="customtooltip c_tool3" data-original-title="data del toolltip numero 3">tooltip</a>
</h6>
<p id="demo"></p>
文章来源: Twitter Bootstrap Popover/Tooltip Bug with Mobile?