jquery anchoring content to certain point
I have a a list of links on my website, th开发者_如何转开发at when then user clicks on one then I display a toolip with some futher options, the links are display as 90x60 image, I am wanting the tooltip that is display to anchor itself on to the top left hand corner of the link/image that has been clicked how can achieve this, below is my current implementation.
$('#wrapper #content ul li a').click(function(e) {
e.preventDefault();
$('#tooltip').remove();
var url = $(this).attr('href');
$.ajax({
type: "POST",
url: url,
data: "",
success: function(html){
var popup = html;
$('#content').append(popup);
$('#tooltip').css({
position: "absolute",
top: e.pageY - 200,
left: e.pageX - 10
});
}
});
});
Any help would be greatly appreciated.
There is jquery plugin for that already: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
There are more http://visionwidget.com/inspiration/web/495-jquery-tooltip-plugins.html
Or you could just write some easy jQ script:
(HTML)
<div class="tooltipped box"></div>
<div class="tooltipped box"></div>
(JS)
$(document).ready(function() {
$('.tooltipped').click(function(){
$('#tooltip').remove();
$('body').append('<div id="tooltip" class="tooltip">This is tooltip</div>');
var p = $(this).position();
$('#tooltip').css({top: p.top, left: p.left+$(this).width()});
});
});
(CSS)
.box { border: 1px solid green; width: 90px; height: 60px; }
.tooltip { border: 1px solid red; width: 50px; height: 50px; position: absolute; }
Use qTip.
$(document).ready(function() {
$("#qtip").qtip({
content: 'ToolTip',
style: {
name: 'red'
},
show: 'mousedown',
hide: 'mouseout',
position: {
target: 'mouse',
adjust: {
mouse: true,
x: -180,
y: -30,
}
}
});
});
Update : Here is my JsFiddle
精彩评论