【问题标题】:jquery ui.sortable with tooltips带有工具提示的 jquery ui.sortable
【发布时间】:2010-05-05 16:46:38
【问题描述】:

在一个页面上,我有一个带有缩略图的可排序列表。 滚动图像时,我想要一个工具提示来显示更大的图像。 我找到了qTip,但也许有更好/更简单的东西?

如何将 imgPath var 从 sortable 连接到 qtip?

var imgPath = '<img src="002171/imm/001.jpg" />';

$("#sortable").sortable();
$("#sortable").disableSelection();

$('#sortable li img').qtip({
    content: {
        text: imgPath
    }
});


<div id="demo">
    <ul id="sortable">
        <li><img src="002171/tn/001.jpg" /></li>
        <li><img src="002171/tn/002.jpg" /></li>
        <li><img src="002171/tn/003.jpg" /></li>
    </ul> 
</div>

【问题讨论】:

  • 如何获取更大图像的 URL,或者可排序列表中的缩略图是否缩小?
  • 我发现的另一个问题是当前版本的 qTip 不适用于 jQuery 1.4.2(参考:craigsworks.com/projects/forums/…

标签: jquery tooltip mouseover jquery-ui-sortable


【解决方案1】:

我为您发布了demo。尽管我很喜欢 qTip,但要弄清楚如何设置它以从当前 HTML 中获取内容并不容易。我花了 20 分钟弄乱它,直到我放弃了。但是,好消息是我知道这个tooltip script 有三个版本,一个是专门为图像预览而制作的。

因此,您需要稍微重新格式化您的 HTML。 &lt;a&gt; 中的 href 包含显示在工具提示中的大图像,而 &lt;img src&gt; 包含缩略图。您还可以通过将文本/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();
});

【讨论】:

  • 嘿 fudgey,非常感谢您的演示。最后我选择了 jqModal。不那么臃肿。
猜你喜欢
  • 2011-11-03
  • 1970-01-01
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多