Input file show live selected image in JCrop

℡╲_俬逩灬. 提交于 2019-12-06 12:14:20
user2903776

You can use:

 jcrop_api.setImage('/crop/demo_files/'+$("#btn_change").val());

to change the pic the drawback is in this way, you can not preview a pic correctly.

<script type="text/javascript">
  jQuery(function($){
    var jcrop_api;
      $('#btn_change').change(function(){
         $("#fielname").val($("#btn_change").val());
          jcrop_api.setImage('/crop/demo_files/'+$("#btn_change").val());

      })

     $('#croppic').click(function(){

      if(checkCoords()){
       var data =  { x: $('#x').val(), y: $('#y').val(),w: $('#w').val(), h: $('#h').val(),fielname:$("#fielname").val() };

        $.post("http://localhost/crop/index.php/welcome/croppic",data,
        function(backdata){
          if(backdata=="success"){
                jcrop_api.release();
                $('#cropmessage').html("<font color=red>thumb pic made please select another one</font>").delay(1000).fadeOut();;
            }
            else
            {
                $('#cropmessage').html("<font color=black>error in process </font>");
            }
        });
        }

      });
      // Create variables (in this scope) to hold the API and image size
    var jcrop_api,
        boundx,
        boundy;

    $('#target').Jcrop({
      onSelect: updateCoords,
      aspectRatio: xsize / ysize
    },function(){
      // Use the API to get the real image size
      var bounds = this.getBounds();
      boundx = bounds[0];
      boundy = bounds[1];
      // Store the API in the jcrop_api variable
      jcrop_api = this;


    });


   function updateCoords(c)
  {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#w').val(c.w);
    $('#h').val(c.h);
  };


    function checkCoords()
    {
        if (parseInt($('#w').val())) return true;
        alert('Please select a crop region then press submit.');
        return false;
    };



  });

</script>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!