這聽起來像你想要的是一個工具提示,而不是一個燈箱(fancybox)。嘗試使用工具提示插件,如jQueryTools Tooltip。
更新:我更新了插件代碼以使用以下HTML佈局。將<a>
標記中的#
替換爲用戶在單擊圖像時要轉到的頁面。另外,這裏是demo。
<ul>
<li>
<a href="#">
<img class="preview" src="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/1s.jpg" data-fullimg="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/1.jpg" data-caption="Lake and a mountain" alt="gallery thumbnail" />
</a>
</li>
<li>
<a href="#">
<img class="preview" src="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/2s.jpg" data-fullimg="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/2.jpg" data-caption="Fly fishing" alt="gallery thumbnail" />
</a>
</li>
<li>
<a href="#">
<img class="preview" src="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/3s.jpg" data-fullimg="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/3.jpg" data-caption="Autumn" alt="gallery thumbnail" />
</a>
</li>
<li>
<a href="#">
<img class="preview" src="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/4s.jpg" data-fullimg="http://www.webinventif.fr/wp-content/uploads/projets/tooltip/02/4.jpg" data-caption="Skiing on a mountain" alt="gallery thumbnail" />
</a>
</li>
</ul>
這是更新後的腳本:
/*
* Image preview script
* powered by jQuery (http://www.jquery.com)
*
* written by Alen Grakalic (http://cssglobe.com)
*
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/
this.imagePreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("img.preview").hover(function(e){
var t = $(this).attr('data-caption');
var c = (t != "") ? "<br/>" + t : "";
$("body").append("<p id='preview'><img src='"+ $(this).attr('data-fullimg') +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
}, function(){
$("#preview").remove();
});
$("img.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
// starting the script on page load
$(document).ready(function(){
imagePreview();
});
您是否希望延長的fancybox的功能或建造它的fancybox以外? – 2011-01-19 14:39:18
我可以去任何一種方式。我的目標是功能。 – fmz 2011-01-19 14:55:02