Jump to content

Tooltip Image and Text wrap


jamiet757

Recommended Posts

I am using a jQuery tooltip package I found here:

http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery

 

I am using it like example #2:

http://cssglobe.com/lab/tooltip/02/

with the caption.

 

The problem is, if the caption is longer than the image is wide, how do I get it to wrap the text around underneath? Right now it just lengthens the gray box and looks ridiculous. I can't use fixed widths because the images are varying widths and the text is varying lengths for each image, so it has to be something that is automatic when the class is called.

 

If anyone can't be troubled to download the files if you need to see the source code I can post it. Just ask.

 

Maybe this is just a problem with the CSS, I don't know. Any help is appreciated!

Link to comment
Share on other sites

Well the problem is that this is how the tooltip is presented:

 

<a href="{ITEM_URL}" class="preview" title="{ITEM_DESC}" name="Author: {ITEM_AUTHOR}" id="{ITEM_IMG2}"><img src="{ITEM_IMG}" border="0" /></a>

 

The {ITEM_DESC} and {ITEM_AUTHOR} are replaced by a description and author text for the image as it is pulled from the database, and they need to reside in the title and name attribute for the <a> tag in order to appear in the caption for the image preview, so how can I assign a class to that?

Link to comment
Share on other sites

You don't assign a class to that. The jquery tooltip will generate some HTML. The container *should* have an ID or a class. Use that to set your width.

I'm sorry, i haven't looked at the specific example. But any script worth it's weight will give you something to target the CSS with. So check the generated HTML to see what it looks like.

Link to comment
Share on other sites

  • 5 weeks later...

Well I still cannot get it to work. I can't set a fixed width for the <p> since each image might be a different width. Here is the javascript code:

 

/*
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*/

this.imagePreview = function(){    
        
        xOffset = 10;
        yOffset = 10;
        
    $("a.preview").hover(function(e){
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        this.n = this.name;
        this.name = "";
        var d = (this.n != "") ? "<br/>" + this.n : "";
        $("body").append("<p id='preview'><img src='"+ this.id +"' alt='"+ this.t +"' />"+ c + d +"</p>");                                 
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("slow");                        
    },
    function(){
        this.title = this.t;
        this.name = this.n;    
        $("#preview").remove();
    });        
    
    $(".preview").mousemove(function(e){
var posY;

if (e.pageY - $(window).scrollTop() + $('#preview').height() >= $(window).height() ) {
posY = $(window).height() + $(window).scrollTop() - $('#preview').height() - 15 ;
} else {
posY = e.pageY - 15;
}
$("#preview")
.css("top",(posY - 15) +"px")
.css("left",(e.pageX + 15) + "px");
});     
};


// starting the script on page load
$(document).ready(function(){
    imagePreview();
});

 

Another question, the section that starts with  $(".preview").mousemove(function(e) prevents the popup from going below the screen, how can I prevent it from going off the sides of the screen as well?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.