How do I get the tooltip background to extend or grow as I input more text?
I have a tooltip background-image that looks like this:
My css is like this:
p#vtip
{
display: none;
position: absolute;
padding: 10px;
left: 5px;
font-size: 13.5pt;
background:url("tooltip-bg.png") no-repeat;
border: 0px solid #a6c9e2;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
z-index: 9999;
height:48px;
width:140px;
color:White;
}
p#vtip #vtipArrow
{
position: absolute;
top: -10px;
left: 5px;
}
This is the jquery code:
this.vtip = function() {
this.xOffset = -10; // x distance from mouse
this.yOffset = 10; // y distance from mouse
$(".vtip").unbind().hover(
function(e) {
this.t = this.title;
this.title = '';
this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
$('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
$('p#vtip #vtipArrow').attr("src", 'images/vtip_arrow.png');
$('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
},
function() {
this.title = this.t;
$("p#vtip").fadeOut("slow").remove();
}
).mousemove(
function(e) {
this.top = (e.pageY + yOffset);
this.left = (e.pageX + xOffset);
$("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
}
);
};
jQue开发者_运维问答ry(document).ready(function($){
vtip();
})
I then apply the css class to the image on my page:
<div title="Bike" class="vtip">
<img alt="" class="img1" style="width: 248px; height: 163px;" src="bike.jpg" /><br />
</div>
But how do i get the tooltip background to extend or grow as i input more text?
This is what I could find for you:
- Using the "chopping" approach you suggested: http://trentrichardson.com/examples/csstooltips/
- More examples of tooltips (some are just css and don't use images so you would avoid your current issue): http://coding.smashingmagazine.com/2007/06/12/tooltips-scripts-ajax-javascript-css-dhtml/
I'd go the CSS way if I were you :D
精彩评论