<div>
<button type="button" class="layui-btn" id="mulUpload">图片上传</button>
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
预览图:
<div class="layui-upload-list" id="mulPreview"></div>
</blockquote>
</div> <link rel="stylesheet" href="/Public/viewer/viewer.min.css">
<script src="/Public/viewer/viewer.min.js"></script> <script>
var mul_imgs = ['http://i.srsr.cc/uploads/info/23021810323430.jpg', 'http://i.srsr.cc/uploads/info/23021810324186.jpg', 'http://i.srsr.cc/uploads/info/23021810324430.jpg', 'http://i.srsr.cc/uploads/info/23021810325261.jpg'] function showImgs() {
$('#mulPreview').empty()
mul_imgs.forEach((img, index) => {
$('#mulPreview').append(`
<div style="background:url(${img}) center center no-repeat;">
<img src="${img}" alt="图${index + 1}" />
<i class="layui-icon layui-icon-close-fill" onclick="delImg(${index})"></i>
</div>
`)
$('#mulPreview').viewer('update')
})
} function delImg(index) {
mul_imgs.splice(index, 1)
showImgs()
} showImgs() layui.use(['upload', 'layer', 'form'], function () {
let upload = layui.upload
let layer = layui.layer
let form = layui.form upload.render({
elem: '#mulUpload'
, url: '__CONTROLLER__/uploadImg' //此处配置你自己的上传接口即可
, multiple: true
, data: { path: '/info/' }
, before: function (obj) {
layer.load()
}
, done: function (res) {
mul_imgs.push(res.data.fullSrc)
console.log('mul_imgs', mul_imgs)
}
, allDone: function (res) {
layer.closeAll('loading')
showImgs()
}
}) })
</script> <style>
#mulPreview {
display: flex;
flex-wrap: wrap;
} #mulPreview div {
margin: 0 16px 16px 0;
position: relative;
width: 150px;
height: 150px;
box-shadow: 0 2px 5px 1px #555;
border-radius: 4px;
background-size: cover !important;
} #mulPreview div img {
width: 100%;
height: 100%;
opacity: 0;
} #mulPreview div i {
position: absolute;
top: -5px;
right: 5px;
font-size: 30px;
color: red;
opacity: 0.6;
}
</style>

最新文章

  1. oschina(开源中国)的Git代码托管平台使用教程
  2. 移动端WEB开发备忘录
  3. JavaScript 基础第七天(DOM的开始)
  4. IEnumerable和List有什么区别?
  5. JsRender系列demo-对null 和boolen类型数据的探讨
  6. hdoj 1859 最小长方形
  7. (转)window.location.search的用法
  8. FZOJ2111:Min Number
  9. jquery选择器基础知识
  10. 属性动画(Property Animation)
  11. 关于异常“The &#39;Microsoft.ACE.OLEDB.12.0&#39; provider is not registered on the local machine”的处理
  12. mybatis中传入一个List集合作为查询条件的参数
  13. hdu--1045--Fire Net,NYOJ--587--dfs--blockhouses
  14. 查找datatable 中的重复记录(只查询一个字段)
  15. springboot-项目获取resources下文件碰到的问题(classPath下找不到文件和文件名乱码)
  16. PG的集群技术:Pgpool-II与Postgres-XC Postgres-XL Postgres-XZ Postges-x2
  17. vue经验 - 细节小知识点汇总(更新中...)
  18. Java序列化总结
  19. webbench的安装
  20. 【Java并发编程】之九:死锁

热门文章

  1. Centos7搭建hadoop3.3.4分布式集群
  2. bat想要写一个卸载软件的脚本,最后宣布失败[未完待续...]
  3. 深入理解JavaScript对象
  4. 找素数(java)
  5. LeetCode算法训练-贪心算法 455.分发饼干 376. 摆动序列 53. 最大子序和
  6. 初始化安装后 Nacos 动态路由配置不生效
  7. Django中获取用户IP方法
  8. vscode 设置默认模板
  9. classmethod 修饰符
  10. (pymssql._pymssql.OperationalError) (8152, b&#39;String or binary data would be truncated.DB-Lib error message 20 018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n&#39;)