javascript - 更改 jcrop 选择的大小

标签 javascript jquery css plugins

当用户输入宽度和高度并单击提交时,我正在尝试调整 jcrop 的选择框

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

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

如果用户点击提交选择框会获取用户指定的宽度高度进入,但在用户尝试移动框后,它变回提交之前的大小。

这是我为此编写的代码:

/* 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>

知道这里的问题是什么吗?

最佳答案

在提交事件时,您需要像这样设置 jCrop 的“setSelect”属性:

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

看看这个例子,你会得到更多的想法: http://deepliquid.com/projects/Jcrop/demos.php?demo=advanced

关于javascript - 更改 jcrop 选择的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728673/

相关文章:

javascript - jquery菜单,悬停并显示:none

jquery - 记住我复选框 : To Store authentication information safely?

javascript - 如何通过代码反转Highcharts中的图表?

javascript - 动画一个绝对定位的 child 溢出的容器

javascript - 如何用span包裹引用的文本?

javascript - Selenium 元素不相互作用

javascript - 如何从异步调用返回响应?

css - 链接颜色没有改变

html - Favicon 和标题在本地显示,但不在网站上显示

javascript - 在 GWT 中使用 SVG