如何制作多个用户编辑资料
我在创建带有用户变化的个人资料图片的HTML网站方面遇到了麻烦。例如,能够在员工配置文件上上传和更改您的个人资料图片。我已经尝试了许多方法,所以我真的不能放下任何代码进行修订,但这是我认为应该有效的方法:
var loadFile = function(event) {
var image = document.getElementById("output");
image.src = URL.createObjectURL(event.target.files[0]);
}
.profile-pic {
color: transparent;
transition: all 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.profile-pic input {
display: none;
}
.profile-pic img {
position: relative;
object-fit: cover;
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.12) !important;
z-index: 0;
}
.profile-pic .-label {
cursor: pointer;
position: absolute;
bottom: 0;
}
.profile-pic:hover span {
background-color: rgba(0, 0, 0, 0.8);
color: #fafafa;
transition: background-color 0.2s ease-in-out;
display: inline-block;
padding: 0.2em;
height: 2em;
text-align: center;
}
<div class="profile-pic">
<img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
<label for="file" class="-label">
<span>Change Photo</span>
</label>
<input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
<hr>
<div class="profile-pic">
<img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
<label for="file" class="-label">
<span>Change Photo</span>
</label>
<input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
I have been having trouble with creating an HTML site with a user-changeable profile picture. For example, being able to upload and change your profile picture on employee profiles. I've tried many methods, so I really can't put any code down for revision, but here's what I thought should work:
var loadFile = function(event) {
var image = document.getElementById("output");
image.src = URL.createObjectURL(event.target.files[0]);
}
.profile-pic {
color: transparent;
transition: all 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.profile-pic input {
display: none;
}
.profile-pic img {
position: relative;
object-fit: cover;
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.12) !important;
z-index: 0;
}
.profile-pic .-label {
cursor: pointer;
position: absolute;
bottom: 0;
}
.profile-pic:hover span {
background-color: rgba(0, 0, 0, 0.8);
color: #fafafa;
transition: background-color 0.2s ease-in-out;
display: inline-block;
padding: 0.2em;
height: 2em;
text-align: center;
}
<div class="profile-pic">
<img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
<label for="file" class="-label">
<span>Change Photo</span>
</label>
<input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
<hr>
<div class="profile-pic">
<img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
<label for="file" class="-label">
<span>Change Photo</span>
</label>
<input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,您更改IMG标签“ ID”。并添加一个参数。
并更改输入文件 - 显示:块。
now you change img tag 'id'. And add a parameter.
and change the input file - display: block.