我用同樣的jQuery插件,但它給了我一些問題,大量元素在同一頁上。測試一些之後,我選擇了這一個:
你可以看到一個工作demo here!
和網頁鏈接Here!
EDITED
按照要求對評論,這裏你有一個基於上述插件的jQuery擴展:
JQUERY
(function($) {
$.fn.tooltipImg = function(options) {
// options
var opts = $.extend({}, $.fn.tooltipImg.defaults, options);
// when the mouse gets over the element
$(this).hover(function(e){
this.t = this.alt;
var c = (this.t != "") ? "<br/>" + this.t : "",
src = ($(this).data("src")!='') ? $(this).data("src") : this.src,
res = '<p class="'+opts.wrapper+'"><img src="'+src+'" alt="Image preview" />'+c+'<p>';
$("body").append(res);
$("."+opts.wrapper)
.css({
"top" : (e.pageY - opts.xOffset) + "px",
"left" : (e.pageX + opts.yOffset) + "px"
})
.fadeIn("fast");
},
function(){
$("."+opts.wrapper).remove();
});
// when the mouse moves while over the element
$(this).mousemove(function(e){
$("."+opts.wrapper)
.css({
"top" : (e.pageY - opts.xOffset) + "px",
"left" : (e.pageX + opts.yOffset) + "px"
});
});
}
// options defaults
$.fn.tooltipImg.defaults = {
xOffset : 10,
yOffset : 30,
wrapper : 'myTooltipImgWindow'
}
})(jQuery);
用法
$(document).ready(function(){
$('.tooltipMe').tooltipImg();
// with options
$('.tooltipMe').tooltipImg({
xOffset : 20,
yOffset : 40,
wrapper : 'myToolTipContainerClass'
});
});
你可以看到這個working Fiddle!
這小提琴說明從跨域圖像,使用相對路徑,並從img
src
。
注意,小提琴下相對路徑是越野車,有時你看到它,你沒有其他時間,但它的作品就好了!
您使用的是什麼插件? –
@RicardoLohmann http://jquery.bassistance.de/tooltip/demo/ –
你能展示你的代碼嗎? –