Jcrop.js jquery图片裁剪插件


Jcrop.js jquery图片裁剪插件

第一步引入bfwone

第二步执行插件代码

示例如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script id="bfwone" data="dep=jquery.17&err=0" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            use(["jquery.Jcrop", "jquery.Jcrop"], function() {
                var jcrop_api;
                var bounds, boundx, boundy;

                $('#cropbox').Jcrop({
                    onChange: showPreview,
                    onSelect: showPreview,
                    aspectRatio: 1
                }, function() {
                    jcrop_api = this;
                    bounds = jcrop_api.getBounds();
                    boundx = bounds[0];
                    boundy = bounds[1];
                });

                function showPreview(coords) {
                    if (parseInt(coords.w) > 0) {
                        var rx = 100 / coords.w;
                        var ry = 100 / coords.h;

                        $('#preview').css({
                            width: Math.round(rx * boundx) + 'px',
                            height: Math.round(ry * boundy) + 'px',
                            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                            marginTop: '-' + Math.round(ry * coords.y) + 'px'
                        });
                    }
                };
            });
        });
    </script>
</head>
<body>
    <h1>Jcrop - Aspect ratio w/ preview pane</h1>

    <table>
        <tr>
            <td>
                <img src="//repo.bfw.wiki/bfwrepo/image/sample4.png" id="cropbox" />
            </td>
            <td>
                <div style="width:100px;height:100px;overflow:hidden;">
                    <img src="//repo.bfw.wiki/bfwrepo/image/sample4.png" id="preview" />
                </div>
            </td>
        </tr>
    </table>

</body>
</html>

官方地址http://deepliquid.com/content/Jcrop.html
立即下载Jcrop.js查看所有js插件

网友评论0

程序员在线工具箱