我所做的導航欄上我的網頁靜態的頂部(在頁面的其餘部分是動態的)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,但它仍然不起作用。 –