Qtip 工具提示未出现

发布于 2024-12-05 12:27:06 字数 3198 浏览 1 评论 0原文

我将页面顶部的导航栏设为静态(页面的其余部分是动态的)。

导航栏位于 ID 为“header”的 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 部分的原因是因为标头中的工具提示和主部分中的工具提示需要不同的参数。

现在的问题是,工具提示在标题中工作正常,但它们在主要部分中不起作用,我想不出任何可能的原因,我尝试了我能想到的一切,但它不起作用。还有其他人知道如何修复它吗?

I made the navbar on the top of my page static (the rest of the page is dynamic)

The navbar is in a div that is given the ID "header" and and everything else is in a div with the ID "main".

I use this code to make tooltips.

This is the 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 });
    });
});

Then this is the 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;
    }

This is the HTML that calls the tooltip.
The first line is for the main section, the second is for the header.

<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>

The reason I used two different javascript sections is because the tooltips in the header and the tooltips in the main section needed different parameters.

Now, the problem is that the tooltips work fine in the header, but they're not working in the main section and I can't think of any possible reason why, I tried everything I could think of and it's not working. Does anyone else know how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾`听者〃 2024-12-12 12:27:06

您是否需要在 div 元素上进行绝对定位(由于您没有指定任何 topleft 值,因此不会出现这种情况)?由于工具提示使用绝对定位并且嵌套在另一个也使用绝对定位的元素中,因此它无法从父元素中“脱离”。

我建议您从 #header#main 样式中删除 position:absolute 规则。或者,从 #header 样式中删除 overflow: auto 规则似乎也有效。

http://jsfiddle.net/tz59G/3/

Do you need absolute positioning on your div elements (it doesn't appear so since you aren't specifying any top or left values)? Since the tooltip uses absolute positioning and is nested within another element which also uses absolute positioning, it can't "break out" from the parent element.

I recommend that you remove the position: absolute rule from the #header and #main styles. Alternatively, removing the overflow: auto rule from the #header style seems to work as well.

http://jsfiddle.net/tz59G/3/

哭泣的笑容 2024-12-12 12:27:06

我终于能够通过将 #header div 设置为固定定位来修复它(因此它保留在窗口的顶部,而没有绝对定位),并且我将 #main div 静态定位并仅通过分页符将其向下移动。

*我认为仅使用一种类型的工具提示会更有效,因此我删除了一种。
*注意我如何设置最小高度,以便我可以显示滚动时 #header div 如何保持在顶部,这就是我想要的效果。

http://jsfiddle.net/tz59G/5/

要查看最终结果,请转到此处:ultimatemmo .webege.com

顶部的导航栏是我的标题 div,其他所有内容都是我的主 div。

注意:该网站不是一个普通的流量网站,我为一个学校项目制作了它,现在它只是一个我不断改进的个人项目。它出现在互联网上的唯一原因是我的朋友和女朋友可以看到我的进展。

I was finally able to fix it by setting the #header div to fixed positioning (so it stays at the top of the window without absolute positioning) and I made the #main div static positioned and moved it down with just page breaks.

*I decided it would be more efficient to only use one type of tooltip, so I removed one.
*Note how I set the min-height so I can display how the #header div stays at the top when you scroll, that is the effect I wanted.

http://jsfiddle.net/tz59G/5/

to see the finished result, go here: ultimatemmo.webege.com

The navbar on top is my header div and everything else is my main div.

Note: that site isn't a normal traffic site, I made it for a school project, now it's just a personal project that I'm constantly improving. The only reason it's on the internet is so my friends and girlfriend can see my progress on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文