Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery拖放图像_Javascript_Jquery - Fatal编程技术网

Javascript 使用jquery拖放图像

Javascript 使用jquery拖放图像,javascript,jquery,Javascript,Jquery,我正在尝试使用拖放创建一个照片编辑器。问题是,当我尝试在html的div中拖放图像时,它会重新加载一个新页面,而不是在div中设置图像。我想将图像放在灰色方框中 $.event.props.push(“数据传输”); $(函数(){ 功能设计(img){ var cW=img.宽度,cH=img.高度; $(“#编辑”) .attr({宽度:cW,高度:cH}); var context=$(“#编辑器”)[0].getContext(“2d”); drawImage(img,0,0);

我正在尝试使用拖放创建一个照片编辑器。问题是,当我尝试在html的div中拖放图像时,它会重新加载一个新页面,而不是在div中设置图像。我想将图像放在灰色方框中



$.event.props.push(“数据传输”);
$(函数(){
功能设计(img){
var cW=img.宽度,cH=img.高度;
$(“#编辑”)
.attr({宽度:cW,高度:cH});
var context=$(“#编辑器”)[0].getContext(“2d”);
drawImage(img,0,0);
var id=context.getImageData(0,0,cW,cH);
var v=[];
对于(变量i=0;i<256;i++){
v、 推(0);
}
对于(变量y=0;y0){
var reader=new FileReader();
reader.onload=函数(e){
desenare($(“#编辑”)
.attr(“src”,e.target.result)[0];
};
reader.readAsDataURL(文件[0]);
}
});
});

请检查jQuery UI的以下代码和源代码链接

可拖动的

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Draggable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 150px; height: 150px; padding: 0.5em; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
</div>


</body>
</html>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Droppable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
  #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
    $( "#droppable" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Drag me to my target</p>
</div>

<div id="droppable" class="ui-widget-header">
  <p>Drop here</p>
</div>


</body>
</html>

jQuery UI可拖动-默认功能
#可拖动{宽度:150px;高度:150px;填充:0.5em;}
$(函数(){
$(“#可拖动”).draggable();
} );
把我拖来拖去

可拖放的

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Draggable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 150px; height: 150px; padding: 0.5em; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
</div>


</body>
</html>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Droppable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
  #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
    $( "#droppable" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Drag me to my target</p>
</div>

<div id="droppable" class="ui-widget-header">
  <p>Drop here</p>
</div>


</body>
</html>

jQuery UI可拖放-默认功能
#可拖动{宽度:100px;高度:100px;填充:0.5em;浮动:左侧;边距:10px 10px 10px 0;}
#可拖放{宽度:150px;高度:150px;填充:0.5em;浮动:左侧;边距:10px;}
$(函数(){
$(“#可拖动”).draggable();
$(“#可拖放”)。可拖放({
drop:函数(事件、用户界面){
$(本)
.addClass(“ui状态突出显示”)
.查找(“p”)
.html(“已删除!”);
}
});
} );
把我拖到我的目标

到这里来


源代码:

e=事件使用e.stopPropagation();