一、代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>blob图片路径加密</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<style>
.inputCons {
width: 100px;
height: 100px;
border: 1px dashed #333;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANIAAADICAMAAACqCk+NAAAA/FBMVEUAAAD/biYwMDIwMTMwMDQwMDMwMTMwMTMwMTIvMDIwMTMwMTMwMDMwMDMwMTMwMDMwMTMxMTMzMzMwMTMvMTMwMTIwMTMwMTMvMTP/byUwMTMxMjIwMTMwMTMwMTMwMDMwMTMvMTP/byYwMTL/ciQvMDMvMTP/byYvMTP/byUwMTP/byUvMTI6Ojo0NDT/byYwMTP/byYwMDP/cCb/byUwMTP/byf/byUwMDAqKir/byb/byb/byb/byUwMTL/byX/byb/byb/byf/cCf/byb/cCb/cCQvMTT/byf/bST/byI1NTX/byb/byb/bib/byb/bST/ZhowMTP/byYoHgVfAAAAUnRSTlMAgIC/QKfltCxi7G1WR/SJMxgT4K2clXVdWU8j+tzUxKCOZEsV2M3GvKyEbGYIA/Lp5cmzk3lIOR8M693WzcW/vZyKcFNQQTsuHA8O4qeGeioKchPaXQAABB1JREFUeNrt3Ydy00AQxvHPiiW59xAXsB3H6YU0CKH3Xlfv/y4wYcjYcCKOcqe71ez/DX6jGZXVnYTZGp6/USNttZfG3gNYbLA6JAOFxRYsVQ7IUO0ibNTqkMH8AlKvEJDRSmtIuQEZL2VT6zaZr4IUOwgpjYpIL4/SqYy0agaUUvcQF9OD9KsdpNMdSq9VpFGe0mwZKVSnVPNhvhGlWwjjrdNc7T3oiOLbgulKRi6I9J+OYTiaD+ZJNMR8GSBRG3NlgUQlzJYJEtUwUzZIRPu4LCskauFPmSHR5TyMJcknVQX8jiUJy6SqgYt4knCLVOUBAExJWI0fHHElYSd2cMSWBC9ucMSXhBVSVeZMQlk9OOJMwh6pqnM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
background-size: 100px 100px;
}
#fileInput {
width: 100px;
height: 100px;
opacity: 0;
}
.tips {
color: #f40;
}
</style>
</head>
<body>
<div class="inputCons">
<input id="fileInput" type="file" name="">
</div>
<p>请选择图片文件</p>
<hr>
<p class="tips"></p>
<img id="imgCons" src="" alt="">
<script>
$("#fileInput").change(function(e) {
e.preventDefault();
let file = this.files[0];
let temp = window.URL.createObjectURL(file);
$('.tips').text("可将控制台输出的图片链接粘贴至其他浏览器进行测试。")
$("#imgCons").attr("src", temp);
console.log("复制blob图片地址至其他浏览器进行测试:\n\n", temp + "\n\n\n");
console.log("%c ", 'margin-left:0px;padding:100px 100px;background-image: url("https://liujianwei695.gitee.io/minifile/images/officialAccount.jpg");background-size: 200px 200px;background-position: center;background-repeat: no-repeat;');
});
</script>
</body>
</html>
二、效果演示
选择图片前
选择图片后
这么happy的事情,有必要六个截图423:
标签:jQuery,HTML,blob类文件对象,图片加密
更多演示案例,查看 案例演示
欢迎评论留言!