我正在寻找一种方法,在移动设备上查看我的网站时禁用qtip2工具提示。在桌面浏览器中,当鼠标悬停时工具提示会出现,在移动设备上它们会在文本输入被触摸时弹出(大多数是通过title=""绑定的)。我只能通过触摸其他地方来让它消失,我怀疑用户在被它惹恼之前不会想到这一点。
我已经尝试过查看API以及在SO上搜索,但我遇到的少数解决方案对我并没有起作用。以下是我尝试过的内容:
我已经尝试过查看API以及在SO上搜索,但我遇到的少数解决方案对我并没有起作用。以下是我尝试过的内容:
$('[title!=""]').qtip({// Grab elements with a title attribute that isn't blank.
style: 'qtip-tipsy',
position: {
target: 'mouse', // Track the mouse as the positioning target
adjust: { x: 5, y: 15 } // Offset it slightly from under the mouse
}
});
//check window size on page load.
if ($(window).width() < 960) {
alert('Less than 960');
//$('[title!=""]').qtip('hide').qtip('disable');
$('[title!=""]').qtip('destroy', true); // Immediately destroy all tooltips belonging to the selected elements
}
else {
//alert('More than 960');
}
});
在测试时,当我将浏览器缩小到960以下并刷新时,警报会触发,因此它似乎正确地读取了该代码。 我尝试了两种方法,第一种是使用hide和disable(当前在上面的示例中被注释掉,同时我尝试了下一个),第二种是使用'destroy' 我还尝试在'position'的最后一个右括号和结束});之前直接添加窗口大小代码。
然后我尝试直接访问api,但我不知道是否做得正确,也找不到包含所有所需代码的示例。 这是我尝试过的:
var tooltips = $('[title!=""]').qtip({// Grab elements with a title attribute that isn't blank.
style: 'qtip-tipsy',
position: {
target: 'mouse', // Track the mouse as the positioning target
adjust: { x: -5, y: -15 } // Offset it slightly from under the mouse
}
});
// Grab the first element in the tooltips array and access it's qTip API
var api = tooltips.qtip('api');
//check window size on page load.
if ($(window).width() < 960) {
alert('Less than 960');
$tooltips.qtip('destroy', true); // Immediately destroy all tooltips belonging to the selected elements
}
else {
//alert('More than 960');
}
});
我已经花了几天时间在这个问题上(还有其他一些无法解决的问题,比如用按钮切换工具提示的开关,但我专注于一件事情)。我希望一些更擅长编码的人能看出我哪里出了错。
if ($(window).width() < 960) { $('[title!=""]').on("click', function () { return false; }); }
- Omar