最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - On Hover, tooltip display an image? - Stack Overflow

matteradmin7PV0评论

What I hope to acplish is write a small jQuery script that will allow me to take the content of a block and trigger a popup whenever someone places their mouse over it. In essense, it's going to be a tooltip with an image in it.

All the tutorials that I have found REPLACE pictures on mouseover, or are tooltips that contain only text. Here is the code:

$(document).ready(function() {
    $('div#block-block-14.block').hover(
        function()  {
            this.tip = this.title;
            $(this).append(
            '<div class="toolTipWrapper">'
            + '<div class="toolTipContent"></div>'
            );
            this.title = "";
            this.width = $(this).width();
            $(this).find('.toolTipWrapper').css({left:this.width-22})
            $('.toolTipWrapper').fadeIn(300);
        },
            function()  {
                $('.toolTipWrapper').fadeOut(100);
                $(this).children().remove();
                    this.title = this.tip;
            }
            );
});

And here is the CSS code:

div#block-block-14.block{ background:url(../images/QuadChartDropShadow.png);}
.toolTipWrapper{width:175px;position:absolute;top:20px;display:none;color:#FFF;font-weight:bold;font-size:9pt}
.toolTipContent{padding: 8 px 15px; background:url(../images/QuadCharDropShadow.png) no-repeat top;}

What I hope to acplish is write a small jQuery script that will allow me to take the content of a block and trigger a popup whenever someone places their mouse over it. In essense, it's going to be a tooltip with an image in it.

All the tutorials that I have found REPLACE pictures on mouseover, or are tooltips that contain only text. Here is the code:

$(document).ready(function() {
    $('div#block-block-14.block').hover(
        function()  {
            this.tip = this.title;
            $(this).append(
            '<div class="toolTipWrapper">'
            + '<div class="toolTipContent"></div>'
            );
            this.title = "";
            this.width = $(this).width();
            $(this).find('.toolTipWrapper').css({left:this.width-22})
            $('.toolTipWrapper').fadeIn(300);
        },
            function()  {
                $('.toolTipWrapper').fadeOut(100);
                $(this).children().remove();
                    this.title = this.tip;
            }
            );
});

And here is the CSS code:

div#block-block-14.block{ background:url(../images/QuadChartDropShadow.png);}
.toolTipWrapper{width:175px;position:absolute;top:20px;display:none;color:#FFF;font-weight:bold;font-size:9pt}
.toolTipContent{padding: 8 px 15px; background:url(../images/QuadCharDropShadow.png) no-repeat top;}
Share Improve this question asked Nov 22, 2011 at 19:50 HectronHectron 3031 gold badge6 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

For tooltip, I will always remend qTip2. The implementation is easy, and the best thing is the creator is supportive, every problem I reported in the Help and Support forum is always having response :)

To render image in the tooltip is easy, can be done in several ways

 <img id='tooltip1' style="display:none;" src="../../Content/HomePage/aboutshop.JPG" />

 $('#aboutshop').qtip({
     content: {
     text: $('#tooltip1') 
     }
 });

Or

 $('a').qtip({
       content: {
        text: '<img src="test.png" />'
        }
  });

You can check many more function here: http://craigsworks./projects/qtip2/docs/

Hope this help :)

Post a comment

comment list (0)

  1. No comments so far