我所做的导航栏上我的网页静态的顶部(在页面的其余部分是动态的)Qtip提示没有出现
导航栏是在给定的ID为“头”,并和其他一切是一个div在ID为“main”的div中。
我使用此代码来制作工具提示。
这是JavaScript/jQuery的/ qtip
$(document).ready(function() {
//Tooltips
$(".tiptrigger").hover(function(){
tip = $(this).find('.tip');
tip.show(); //Show tooltip
}, function() {
tip.hide(); //Hide tooltip
}).mousemove(function(e) {
var mousex = e.pageX + 20; //Get X coodrinates
var mousey = e.pageY + 20; //Get Y coordinates
var tipWidth = tip.width(); //Find width of tooltip
var tipHeight = tip.height(); //Find height of tooltip
//Distance of element from the right edge of viewport
var tipVisX = $(window).width() - (mousex + tipWidth);
//Distance of element from the bottom of viewport
var tipVisY = $(window).height() - (mousey + tipHeight);
if (tipVisX < 20) { //If tooltip exceeds the X coordinate of viewport
mousex = e.pageX - tipWidth - 20;
} if (tipVisY < 20) { //If tooltip exceeds the Y coordinate of viewport
mousey = e.pageY - tipHeight - 20;
}
//Absolute position the tooltip according to mouse position
tip.css({ top: mousey, left: mousex });
});
});
$(document).ready(function() {
//Tooltips
$(".tipheader").hover(function(){
tip = $(this).find('.tip');
tip.show(); //Show tooltip
}, function() {
tip.hide(); //Hide tooltip
}).mousemove(function(e) {
var mousex = e.pageX + 30; //Get X coodrinates
var mousey = e.pageY + -20; //Get Y coordinates
var tipWidth = tip.width(); //Find width of tooltip
var tipHeight = tip.height(); //Find height of tooltip
//Distance of element from the right edge of viewport
var tipVisX = $(window).width() - (mousex + tipWidth);
//Distance of element from the bottom of viewport
var tipVisY = $(window).height() - (mousey + tipHeight);
if (tipVisX < 20) { //If tooltip exceeds the X coordinate of viewport
mousex = e.pageX - tipWidth - 20;
} if (tipVisY < 20) { //If tooltip exceeds the Y coordinate of viewport
mousey = e.pageY - tipHeight - 20;
}
//Absolute position the tooltip according to mouse position
tip.css({ top: mousey, left: mousex });
});
});
那么这是CSS
.tip {
color: #fff;
background: #1d1d1d;
display: none; /*--Hides by default--*/
padding: 10px;
position: absolute;
z-index: 1000;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
这是调用提示的HTML。 第一行是主要部分,第二行是首部。
<a href="LINK URL" class="tiptrigger"><img src="IMAGE URL" alt="" /><span class="tip">CONTENT</span></a>
<a href="LINK URL" class="tipheader"><img src="IMAGE URL" alt="" /><span class="tip">CONTENT</span></a>
我使用了两种不同的javascript部分的原因是因为在标头中的工具提示和工具提示在主部分需要不同的参数。
现在,问题是工具提示在标题中工作正常,但它们不在主要部分工作,我想不出任何可能的原因,我尝试了所有我能想到的事情,而不是加工。其他人知道如何解决它?
您不需要两个'$(document).ready'函数。 – Jack
似乎为我工作:http:// jsfiddle。net/tz59G/ 您可以验证.tiptrigger元素的事件处理程序是否正在触发?也许在函数中放置一些'console.log()'语句。然后,您可以开始将其缩小为javascript,CSS或标记问题。 – RoccoC5
@杰克,好吧,我改变了它,所以它只有一个$(document).ready,但它仍然不起作用。 –