2013-04-29 105 views
3

我使用http://cssglobe.com/lab/tooltip/02/来显示图像预览,如果您转到此页上的检查元素并设置float:right;并将鼠标悬停到窗口最近的图像上,预览图像将隐藏在屏幕后面。我想要显示在左侧,如果徘徊的图像是极右,反之亦然。任何帮助表示赞赏。如何在缩略图悬停上显示图像预览

下面是正在处理的鼠标悬停和mousemove

/* 
* 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(); 
}); 

回答

4

我写的东西有点不同,然后准确地读出你的问题:(我希望它仍然会帮助你的JS,所有你必须改变是摆脱Math.min,并有一个简单的IF,当它是真的改变偏移一点。

trc_x = Math.min(trc_x + event.pageX, Mx); 
trc_y = Math.min(trc_y + event.pageY, My); 

http://jsfiddle.net/V5JCq/9/