Javascript 文档中的作物内容并将作物面积缩放到另一个div
我在这方面的目标是能够裁剪html文档的任何部分(图像、白色背景),并能够将相同的裁剪区域缩放到页面底部的红色正方形。这是构建剪贴工具的最后一步(这只是对web工具的一个实验),我现在需要最后的推动,如果不使用现有的存储库,我似乎无法正确地解决这个问题。我可以这样做,但这毕竟不是尝试的目的。有什么帮助吗?请随意编辑小提琴ofc HTMLJavascript 文档中的作物内容并将作物面积缩放到另一个div,javascript,jquery,html,css,web,Javascript,Jquery,Html,Css,Web,我在这方面的目标是能够裁剪html文档的任何部分(图像、白色背景),并能够将相同的裁剪区域缩放到页面底部的红色正方形。这是构建剪贴工具的最后一步(这只是对web工具的一个实验),我现在需要最后的推动,如果不使用现有的存储库,我似乎无法正确地解决这个问题。我可以这样做,但这毕竟不是尝试的目的。有什么帮助吗?请随意编辑小提琴ofc HTML <div id="selection_box"></div> <img src="http://popcultureblog.da
<div id="selection_box"></div>
<img src="http://popcultureblog.dallasnews.com/files/2012/10/NORAH1BYNOAHABRAMS_27933966.jpeg" id="image_box">
<div id="captured_box"></div>
CSS
* {
-moz-user-select: none;
-webkit-user-select: none;
}
#selection_box {
-webkit-animation: blackwhite 3s infinite;
display: none;
position: absolute;
border: 1px dashed #000000;
background: transparent;
width: 0;
height: 0;
z-index: 1;
}
@-webkit-keyframes blackwhite {
40% {
border-color:white;
}
100% {
border-color:black;
}
}
#image_box {
position: absolute;
top: 75px;
width: 700px;
height: 370px;
}
#captured_box {
position: absolute;
top: 500px;
left: 100px;
width: 100px;
height: 100px;
background-color: red;
}
这将解决您实现的问题(在这里,鼠标也可以从单击点向左和向上移动)
功能鼠标移动(e){
var mxy=getCursorPosition(e);
var-box=document.getElementById(“选择框”);
var right=mxy[0]>box.orig_x;
var left=!right;
var up=mxy[1]始终在您的帖子上发布相关代码。出于某种原因,您不允许发布指向JSFIDLE的链接,而不允许发布代码。如果您的FIDLE被删除,您的代码将不会有任何参考。只需使用缩放
以适应所需的框大小?这里的要点是,我缺乏理解如何保持选择区域“复制”特定内容,然后将其转换为完全不同的div…解决方案是否需要在所有主要浏览器上运行?Firefox有一种镜像元素的方法,但它是唯一支持该功能的浏览器。
* {
-moz-user-select: none;
-webkit-user-select: none;
}
#selection_box {
-webkit-animation: blackwhite 3s infinite;
display: none;
position: absolute;
border: 1px dashed #000000;
background: transparent;
width: 0;
height: 0;
z-index: 1;
}
@-webkit-keyframes blackwhite {
40% {
border-color:white;
}
100% {
border-color:black;
}
}
#image_box {
position: absolute;
top: 75px;
width: 700px;
height: 370px;
}
#captured_box {
position: absolute;
top: 500px;
left: 100px;
width: 100px;
height: 100px;
background-color: red;
}
function mousemove(e) {
var mxy = getCursorPosition(e);
var box = document.getElementById("selection_box");
var right=mxy[0]>box.orig_x;
var left=!right;
var up=mxy[1]<box.orig_y;
var down=!up;
if(up && right){
box.style.top = mxy[1] + "px";
}
else if(up && left){
box.style.left = mxy[0] + "px";
box.style.top = mxy[1] + "px";
}
else if(down && left){
box.style.left = mxy[0] + "px";
box.style.top = mxy[1] - "px";
}
box.style.width = (Math.abs(mxy[0] - box.orig_x)) + "px";
box.style.height = (Math.abs(mxy[1] - box.orig_y)) + "px";
}