改变jcrop选择的大小

时间:2015-04-19 10:35:57

标签: javascript jquery css plugins

当用户输入宽度和高度并点击selection box时,我尝试调整jcrop的submit

我在这里举了一个例子:http://pixelbypixel.comli.com/jcrop/

jcrop插件:http://deepliquid.com/projects/Jcrop/demos.php

如果用户点击submitselection box正在获取用户输入的widthheight,但在用户尝试移动该框后,它会更改回来到submit之前的大小。

这是我写的代码:

/* jcrop when page loads */
var jcrop_api;
function initJcrop(oImg){
        oImg.Jcrop({},function(){
           jcrop_api = this;
           jcrop_api.animateTo([100,100,400,300]);
        });
    };      
jQuery(function(jQuery){
    initJcrop(jQuery('#jcrop_target'));
});

/* box number when page loads */
function showCoords(c){
    jQuery('#w').val(c.w);
    jQuery('#h').val(c.h);
};

/* size when submit */
jQuery('.update-size').click(function(){
    var ancho = jQuery('#w').val();
    var altura = jQuery('#h').val();
    jQuery('.jcrop-holder > div:nth-child(1)').css('height', altura);
    jQuery('.jcrop-holder > div:nth-child(1)').css('width', ancho);
});

这是标记:

<img src="img/test.jpg" id="jcrop_target">
<div>
    <p>Define your own dimensions in CM:</p>
    <form>
        <label>Width: <input type="text" size="4" id="w" name="w" value="360"></label>
        <label>Height: <input type="text" size="4" id="h" name="h" value="360"></label>
        <a href="javascript:void(0)" class="update-size">submit</a>
    </form>
</div>

知道这可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

在提交事件时,您需要设置jCrop的'setSelect'属性,如下所示:

jcrop_api.setSelect([0,0,ancho,altura]);

查看此示例,您将获得更多想法: http://deepliquid.com/projects/Jcrop/demos.php?demo=advanced