这是我的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为选择图像区域编写的。现在我希望在新的div中选择图像。希望您理解我要问的问题。

最佳答案

答案在这里: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 });
});

希望我能帮上忙。 :)

09-15 17:30