Jcrop预览已移动
Jcrop preview shifted?
我正在使用Jcrop,虽然它运行良好,但预览图像看起来被输入了错误的坐标。我怀疑我的javascript函数是罪魁祸首,但我已经挣扎了几个小时,看不到任何解决方案。有什么帮助吗?这是我的代码:
http://jsfiddle.net/1vetnqu0/
HTML:
<div class="content">
<a class="lol" href="#este">Upload image!</a>
</div>
<div id="este" class="mfp-hide popup zoom-anim-dialog">
<h4>Upload image</h4>
<form id="form1">
<input type='file' id="imgInp" />
<img id="blah" class="crop" src="#" alt="your image" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
</form>
<div style="width:100px;height:100px;overflow:hidden; margin-top: 20px;">
<img id="preview" />
</div>
</div>
JAVASCRIPT:
$(document).ready(function() {
$('.lol').magnificPopup({
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: 'my-mfp-slide-bottom'
});
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
$('#preview').attr('src', e.target.result);
$('.crop').Jcrop({
onSelect: updateCoords,
onChange: showPreview,
aspectRatio: 1,
bgOpacity: .4,
setSelect: [ 100, 100, 50, 50 ]
});
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
console.log(this);
readURL(this);
});
function updateCoords(c)
{
console.log(c);
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function showPreview(coords)
{
var rx = 100 / coords.w;
var ry = 100 / coords.h;
$('#preview').css({
width: Math.round(rx * 500) + 'px',
height: Math.round(ry * 500) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
非常感谢!
我以前也遇到过类似的jCrop问题。这里有几个道具可以解决你的问题:trueSize和boxWidth,boxHeight
参考页:http://deepliquid.com/content/Jcrop_Sizing_Issues.html
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何在android中使用phonegap将文件从一个文件夹移动/复制到另一个文件夹
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- FabricJs-限制主对象内添加对象的移动区域
- 如何从画布上的某个移动事件中获取X和Y
- 触摸移动时切换到新元素
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 停止jQuery UI滑块移动超过给定值
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- JQuery移动动态分区页面
- XMLHttpRequest在移动设备上的chrome上不起作用
- 如何使bxslider仅在移动视图中处于活动状态
- css停止图像在滚动中移动
- jquery移动对齐按钮取决于内容大小
- 背景图像顶部的滚动图像不移动
- 如何在react js中移动第二个组件
- DataTables在表之间移动行
- Jcrop预览已移动