gpt4 book ai didi

javascript - 无法使用 FileReader 操作元素

转载 作者:行者123 更新时间:2023-12-02 14:53:00 25 4
gpt4 key购买 nike

我已经添加了一个 jfiddle 来查看。基本上我想要完成的是允许用户上传图片并能够在页面上移动它。当我使用 Chrome 调试器时,我可以看到它成功更新了 jQuery 第 27 行和第 28 行的内联样式,但图像没有正确响应。有任何想法吗?提前致谢。

https://jsfiddle.net/swam/jxoagk86/

        $(document).ready(function(){
$(function(){
$("#file").change(function(){
var reader = new FileReader();
reader.onload = function(e){
$('#pic').attr("style", "height:200; width: 300;");
$('#pic').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
});
});
});

$(document).ready(function(){
$("#pic").mousedown(function(){
$(this).data("dragging", true);
});

$("#pic").mouseup(function(){
$(this).data("dragging", false);
});
$("#pic").mousemove(function(e) {
if (!$(this).data("dragging"))
return;
$(this).css("left", e.clientX - $(this).width()/2);
$(this).css("top", e.clientY - $(this).height()/2);
});
});

最佳答案

您需要在 img#pic 标签中添加一个 css position:relative;

https://jsfiddle.net/jxoagk86/1/

img#pic {
position: relative;
}

关于javascript - 无法使用 FileReader 操作元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36027605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com