javascript - 缩放图像灯箱

标签 javascript jquery jquery-plugins

我正在寻找一个灯箱 jQuery 插件,它可以像 Highslide 一样缩放单击的图像 http://highslide.com/#examples但它必须小(Highslide 的核心为 57kb)并且响应灵敏。 它可以非常简单。我不需要画廊等。

您知道好的替代方案吗?

最佳答案

jsBin demo

您需要的一切:
data-darkbox 添加到您的图像中:

<img data-darkbox src="image.jpg">

CSS:

/* DARKBOX STYLES */
#darkbox{
    position:fixed;
    z-index:9999;
    background:rgba(0,0,0,0.8) no-repeat none 50%/contain;
    box-shadow:0 0 0 3000px rgba(0,0,0,0.8);
    opacity:0; visibility:hidden;
}
#darkbox.on{ 
    opacity:1; visibility:visible;
    height:90% !important; width:90% !important;
    left:5% !important; top:5% !important;
}
#darkbox:after{
    position:absolute;
    right:0; top:0;
    font-size:2em;
    content:"\2A2F";
    color:#fff;
    cursor:pointer;
}

jQuery

var $darkbox = $("<div/>",{id:"darkbox"}).on("click", function(){
    $(this).removeClass("on");
}).appendTo("body");
$('img[data-darkbox]').css({cursor:"pointer"}).on("click",function(){
    var o=this.getBoundingClientRect();
    $darkbox.css({
        transition:"0s",
        backgroundImage:"url("+this.src+")",
        left:o.left, top:o.top,
        height:this.height, width:this.width
    });
    setTimeout(function(){
        $darkbox.css({transition:".8s"}).addClass("on"); 
    },5);
});

关于javascript - 缩放图像灯箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29202831/

相关文章:

javascript - 如何在重新初始化之前销毁 JQuery 插件实例? (照片刷卡)

javascript - 跨域文件

Javascript 类列表未按预期工作

jquery - 如何在 CSS3 中实现径向/饼形菜单?

css - 如何更改 Select NoUISlider JQuery 插件的句柄?

javascript - 停止正在执行的 jquery,然后从它离开的地方恢复

javascript - 使用下面的 jquery ajax 缓存代码时,jquery ajax 中的回调不起作用

javascript - 需要隐藏具有禁用属性的选项

jquery-ui - struts2 jquery插件将html包装为返回的id

jquery - PhoneGap + jQuery Mobile在Android 2.1访问HTML5 Sqlite数据库问题