一款Zoomify – jQuery缩放图片js

jQuery缩放图片js效果-lightbox插件

  下载好之后放到项目中:

一、静态图片使用

   引入zoomify文件 和 jQuery文件

<!-- 进入Bootstrap的css样式 -->
    <link href="./bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet">
    <link href="./plugins/zoomify/css/zoomify.css" rel="stylesheet">

<!-- 引入jQuery  -->
    <script src="./jquery/jquery-1.12.4.js"></script>
<!-- 引入Bootstrap 的所有JavaScript 插件。 -->
    <script src="./bootstrap-3.3.7/js/bootstrap.js"></script>
    <script src="./plugins/zoomify/js/zoomify.js"></script>

 1、 简单使用: 给 <img> 添加 .zoomify 类,

        <div class="row">
            <div class="col-sm-4 col-md-4">
                <div class="thumbnail">
                    <img class="zoomify" src="./image/abc123.jpg"  alt="缩略图">
                    <div class="caption">
                        <h3>缩略图标签</h3>
                        <p>一些示例文本。</p>
                        <p>
                            <a href="#" class="btn btn-primary" role="button"> 按钮1</a>
                            <a href="#" class="btn btn-primary" role="button"> 按钮2</a>
                        </p>
                    </div>
                </div>
            </div>
        </div>

    JavaScript: 定义id 等其他选择器都可以

$(function () {
    $('.zoomify').zoomify();
});

     点击图片之后或有 遮蔽层。

2、属性: 添加动画效果

名称类型默认值说明
duration整数200动画持续时间
easing字符串linear动画持续时间
scale整数/浮点数0.9图片最大缩放比例
<img class="zoomify" data-duration="1000" data-easing="linear" data-scale="0.8" src="./image/abc123.jpg"  alt="缩略图">

3、方法:通过按钮实现放大缩小

名称说明举例
zoom放大或缩小$(‘.zoomify’).zoomify(‘zoom’);
zoomIn放大$(‘.zoomify’).zoomify(‘zoomIn’);
zoomOut缩小$(‘#myImage’).zoomify(‘zoomOut’);
reposition重新调整$(‘#myImage’).zoomify(‘reposition’);
       <div class="row">
            <div class="col-sm-4 col-md-4">
                <div class="thumbnail">
                    <img id="zoomifyImg" class="zoomify" data-duration="1000" data-easing="linear" data-scale="0.8" src="./image/abc123.jpg"  alt="缩略图">
                    <div class="caption">
                        <h3>缩略图标签</h3>
                        <p>一些示例文本。</p>
                        <p>
                            <a href="#" class="btn btn-primary" role="button"> 按钮1</a>
                            <a href="#" class="btn btn-primary" role="button"> 按钮2</a>
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-sm-4 col-md-4" style="position: absolute; right: 0; z-index: 2000;">
                <button type="button" class="btn btn-primary" id="zoom">放大/缩小</button>
                <button type="button" class="btn btn-primary" id="zoomin">放大</button>
                <button type="button" class="btn btn-success" id="zoomout">缩小</button>
            </div>
        </div>

JavaScript: 定义id 等其他选择器都可以

$(function () {
    $('.zoomify').zoomify();
    $("#zoom").on("click",function () {
        $(".zoomify").zoomify("zoom")
    } )
    $("#zoomin").on("click",function () {
        $(".zoomify").zoomify("zoomIn")
    } )
    $("#zoomout").on("click",function () {
        $(".zoomify").zoomify("zoomOut")
    } )
});

    

4、事件:不常用

名称说明
zoom-in.zoomify放大前的事件
zoom-in-complete.zoomify放大后的事件
zoom-out.zoomify缩小前的事件
zoom-out-complete.zoomify缩小后的事件

JavaScript

$(function () {
    var $zoomify = $('.zoomify');
    $zoomify.zoomify().on({
        'zoom-in.zoomify': function() {
            alert('开始放大');
        },
        'zoom-in-complete.zoomify': function() {
            alert('放大完成');
        },
        'zoom-out.zoomify': function() {
            alert('开始缩小');
        },
        'zoom-out-complete.zoomify': function() {
            alert('缩小完成');
        },
    });
});

 二、动态添加的图片

 

 

 

下载及详情参考:http://www.sj520.cn/downloadDetail/16/1774.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您需要一个支持图像缩放以及点线框等批注的 JS 插件,我可以为您推荐一款功能强大的插件:OpenSeadragon。它是一个高性能的图像查看器,支持各种类型的图像文件,并且可以在图像上添加注释、标记和矩形框等。以下是使用 OpenSeadragon 的示例代码: ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>OpenSeadragon Demo</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/openseadragon.min.css"> </head> <body> <h1>OpenSeadragon Demo</h1> <div id="openseadragon"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/openseadragon.min.js"></script> <script> var viewer = OpenSeadragon({ id: "openseadragon", prefixUrl: "https://openseadragon.github.io/openseadragon/images/", tileSources: "example.dzi", showNavigationControl: true, zoomInButton: "zoom-in", zoomOutButton: "zoom-out", homeButton: "home", fullPageButton: true }); viewer.addHandler("open", function() { var overlay = viewer.svgOverlay(); overlay.node().setAttribute("class", "annotation-overlay"); var rect = overlay.node().appendChild(document.createElementNS(overlay.svgns, "rect")); rect.setAttribute("x", viewer.viewport.imageToViewerX(100)); rect.setAttribute("y", viewer.viewport.imageToViewerY(100)); rect.setAttribute("width", viewer.viewport.imageToViewerX(200) - viewer.viewport.imageToViewerX(100)); rect.setAttribute("height", viewer.viewport.imageToViewerY(200) - viewer.viewport.imageToViewerY(100)); rect.setAttribute("fill-opacity", 0); rect.setAttribute("stroke", "#ff0000"); rect.setAttribute("stroke-width", 2); rect.setAttribute("stroke-opacity", 1); }); </script> </body> </html> ``` 在这个示例中,您需要将 OpenSeadragon 的 CSS 和 JS 引入到您的 HTML 文件中。然后,您需要在 HTML 文件中放置一个 `div` 元素,并给它一个 ID,以便在 JS 中引用它。接下来,您需要使用 `OpenSeadragon()` 函数创建一个查看器,并将其附加到 `div` 元素上。在 `tileSources` 参数中,您需要指定您要查看的图像文件,它可以是 Deep Zoom Image (DZI)、Google Maps Tile (TMS)、Zoomify Image (ZIF) 等格式。最后,在 `open` 事件处理函数中,您可以使用 `svgOverlay()` 函数创建一个 SVG 叠加层,并在其中添加矩形框等注释。 当您使用 OpenSeadragon 查看图像时,您可以使用鼠标滚轮缩放图像,使用鼠标左键拖动图像,使用鼠标右键或 Ctrl + 鼠标左键添加注释、标记和矩形框等。您可以在插件的官方网站上找到更多有关 OpenSeadragon 的信息和文档:https://openseadragon.github.io/。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值