如何在新的分区中显示ImgAreaSelect选择的图像

how can i show selected image by ImgAreaSelect in a new div

本文关键字:显示 ImgAreaSelect 选择 图像 分区      更新时间:2023-09-26

这是我为ImgAreaSelect:编写的代码

    <!DOCTYPE html>
    <html>
    <head>         
      <link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
      <script type="text/javascript" src="scripts/jquery.min.js"></script>
      <script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js">    </script>      
        <script type="text/javascript">
        $(document).ready(function () {
      $('#ladybug_ant').imgAreaSelect({ maxWidth: 200, maxHeight: 150, handles: true });
    });    
    </script>
    </head>
    <body>
   <img src="http://jotform.org/demo/jquery-image-area-select-plugin/images/sweet-dogs.jpg" id="ladybug_ant" style="height:200px;width:300px;"><br>

</body>
</html>

这是我为ImgAreaSelect为select图像区域编写的代码。现在我想在新的分区中选择图像。我希望你能理解我想问的问题。

答案如下:http://odyniec.net/projects/imgareaselect/examples-callback.html-以现场为例!!

    function preview(img, selection) {
    var scaleX = 100 / (selection.width || 1);
    var scaleY = 100 / (selection.height || 1);
    $('#ferret + div > img').css({
        width: Math.round(scaleX * 400) + 'px',
        height: Math.round(scaleY * 300) + 'px',
        marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
        marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
    });
}
$(document).ready(function () {
    $('<div><img src="ferret.jpg" style="position: relative;" /><div>')
        .css({
            float: 'left',
            position: 'relative',
            overflow: 'hidden',
            width: '100px',
            height: '100px'
        })
        .insertAfter($('#ferret'));
    $('#ferret').imgAreaSelect({ aspectRatio: '1:1', onSelectChange: preview });
});

希望我能帮忙