修改Jquery以展开不同位置的每张照片

Modify Jquery to expand each photo in different position

本文关键字:张照片 照片 位置 Jquery 修改      更新时间:2023-09-26

我一直在寻找一个脚本,它可以在鼠标悬停时展开照片。

这是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();
});

我想把每张照片展开到我想要的不同的绝对位置。

要查看演示:http://cssglobe.com/lab/tooltip/02/

感谢

问候

要使所有预览都发生在同一位置,请更改中这些行的坐标

.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")

编写所需坐标以代替e.pageY - xOffsete.pageX + yOffset

$("your id").click(function(event) {
  event.preventDefault();
});

单击的锚点不会将浏览器带到新的URL。