我为您发布了demo。就像我喜欢qTip一样,要弄清楚如何设置它来抓取当前HTML中的内容并不容易。我花了20分钟搞定它,直到我放弃了。但是,好消息是我知道tooltip script有三个版本,其中一个专门用于图像预览。
所以你需要重新格式化你的HTML。 <a>
中的href
包含显示在工具提示中的大图像,而<img src>
包含缩略图。您也可以在工具提示中加入标题,方法是在链接的标题属性中添加文本/ HTML(请参阅下面代码中的第一张图片)。
HTML
<div id="demo">
<ul id="sortable">
<li><a class="preview" href="01.gif" title="This image has a caption"><img src="01.gif" /></a></li>
<li><a class="preview" href="02.gif"><img src="02.gif" /></a></li>
<li><a class="preview" href="03.gif"><img src="03.gif" /></a></li>
<li><a class="preview" href="04.gif"><img src="04.gif" /></a></li>
<li><a class="preview" href="05.gif"><img src="05.gif" /></a></li>
<li><a class="preview" href="06.gif"><img src="06.gif" /></a></li>
<li><a class="preview" href="07.gif"><img src="07.gif" /></a></li>
<li><a class="preview" href="08.gif"><img src="08.gif" /></a></li>
<li><a class="preview" href="09.gif"><img src="09.gif" /></a></li>
<li><a class="preview" href="10.gif"><img src="10.gif" /></a></li>
</ul>
</div>
CSS
.preview { cursor:pointer; }
#preview {
color: #ddd;
background: #222;
border: 1px solid #333;
padding: 5px;
display: none;
opacity: 0.9;
filter: alpha(opacity=90);
text-align: center;
}
脚本
$(document).ready(function(){
$("#sortable").sortable();
$("#sortable").disableSelection();
});
// You should load the image preview script below separately
// but I've included it here for completeness
/*
* 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 */
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
}, function(){
this.title = this.t;
$("#preview").remove();
});
$("a.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();
});
你如何获得的URL更大的图像或在排序列表缩小缩略图? – Mottie 2010-05-05 19:41:10
我发现的另一个问题是,当前版本的qTip不支持jQuery 1.4.2(参考:http://craigsworks.com/projects/forums/thread-qtip-still-not-working-with-jquery- 1-4-2) – Mottie 2010-05-06 18:45:09