jquery ui.sortable 带有工具提示

发布于 2024-08-31 02:56:19 字数 702 浏览 7 评论 0原文

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

如何将 imgPath var 从可排序连接到 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>

On a page I have a sortable list with thumbnails.
When rolling over the images I wanted a tooltip to show a bigger image.
I found qTip, but maybe there is something better / easier?

How can I connect the imgPath var from the sortable to the 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涫野音 2024-09-07 02:56:19

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

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

I posted a demo for you. As much as I like qTip, it isn't easy to figure out how to set it up to grab content from within the current HTML.. I spent 20 minutes messing with it until I gave up. But, good news is I do know that this tooltip script has three versions, and one is specifically made for image previews.

So you'll need to reformat your HTML a bit. the href in the <a> contains the large image that shows up in the tooltip while the <img src> contains the thumbnail. You can also include a caption in the tooltip by adding text/HTML into the title attribute of the link (see the first image in the code below).

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;
}

Script

$(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();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文