0

我有一小排缩略图图像,我使用悬停效果滚动使用我在这里找到的 jquery 工具提示插件:http: //cssglobe.com/easyest-tooltip-and-image-preview-using-jquery

该插件默认工作正常,但我无法成功控制预览图像的位置。(特别是 - 使预览显示在缩略图的左上角)

我的大部分图片都在页面的右侧,所以我需要预览显示在缩略图的左上角。当我在 javascript 中调整 y 或 x 偏移变量时,光标和预览图像开始闪烁,就像它们处于某种循环中一样。

这是CSS:

<style>
#screenshot{
    position:absolute;
    border:1px solid #ccc;
    background:#333;
    padding:5px;
    display:none;
    color:#fff;
    }
</style>

这是Javascript:

this.screenshotPreview = 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.screenshot").hover(function(e){
        this.t = this.title;
        this.title = "";    
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                
        $("#screenshot")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("fast");                        
    },
    function(){
        this.title = this.t;    
        $("#screenshot").remove();
    }); 
    $("a.screenshot").mousemove(function(e){
        $("#screenshot")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });         
};


// starting the script on page load
$(document).ready(function(){
    screenshotPreview();
});

这是我的 HTML:

<a href="#" class="screenshot" rel="/images_no/products_large/img_10.png" title="Available Drawer Knob Options"><img src="/images_no/products_small/img_10.png" border="0"></a>
4

1 回答 1

0

尝试更改为#screenshot 的CSS 样式

#screenshot{
    position:absolute;
    border:1px solid #ccc;
    background:#333;
    padding:5px;
    display:none;
    color:#fff;
    margin-top:-300px; /* height of the container */
    margin-left:-480px; /* width of the container */
}
于 2012-10-30T14:33:32.223 回答