选择图像的一部分,并使用jQuery检索其坐标
Select a portion of an image and retrieve its coordinates with jQuery
我需要一种方法让用户通过调整透明矩形的大小或点击并拖动选择区域来选择图像的部分(就像在桌面操作系统中一样),这两种方法都适用。然后我需要用jQuery检索所选区域的坐标。
请推荐可能有帮助的样本或教程(如果有的话)、方法或API文档部分。
请参阅Jcrop及其演示。
<!-- This is the image we're attaching Jcrop to -->
<img src="demo_files/pool.jpg" id="target" alt="Flowers" />
脚本:
<script type="text/javascript">
jQuery(function($){
$('#target').Jcrop({
onChange: showCoords,
onSelect: showCoords
});
});
// Simple event handler, called from onChange and onSelect
// event handlers to show an alert, as per the Jcrop
// invocation above
function showCoords(c)
{
alert('x='+ c.x +' y='+ c.y +' x2='+ c.x2 +' y2='+ c.y2)
alert('w='+c.w +' h='+ c.h)
};
</script>
<html>
<head>
<title>Image Processs</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.15/css/jquery.Jcrop.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.15/js/jquery.Jcrop.js"></script>
</head>
<body>
<img src="https://i.stack.imgur.com/UYYqo.jpg" alt="" id="image">
<script>
$(document).ready(function(){
$('#image').Jcrop({
onSelect: function(c){
console.log(c);
console.log(c.x);
console.log(c.y);
console.log(c.w);
console.log(c.h);
}
})
})
</script>
</body>
</html>
相关文章:
- JQUERY检索并删除以前的兄弟姐妹
- 使用 jQuery 检索子按钮的特定父级
- 单击按钮后从jQuery检索文本到HTML
- 使用 Javascript 或 jQuery 检索会话变量的简单快捷的方法
- 使用JQuery检索元素数据
- JQuery检索数据,但如果退出,则获取默认值
- jQuery检索最接近唯一选择器的内容
- jQuery:检索日期选择器日期,检查是否在日期范围内,显示/隐藏字段
- 如何使用JQuery检索完整的DOM结构,其中输入只是一个按钮
- 使用jquery检索父节点的子节点
- 如何使用jQuery检索onSubmit事件
- 如何使用 JQuery 检索具有特定类的 span 元素中的文本,该元素位于单击的对象内
- 如何使用 JQuery 检索设置了特定类的所有标签的列表,然后从这些标签中删除内容
- 将数据属性添加到标记并使用 JQuery 检索它
- 如何使用正则表达式或 jQuery 检索 URL 的最后一部分
- jQuery检索顶级XML节点
- 使用 jquery 检索原始 html,而不是渲染的 html
- JQuery 检索文本而不是选择列表的值
- 使用 jQuery 检索 HTML 格式的内容
- 使用 jQuery 检索属性中的文本