layui多圖上傳實現(xiàn)刪除功能的例子
更新時間:2019年09月23日 15:29:16 作者:蠶豆的生活
今天小編就為大家分享一篇layui多圖上傳實現(xiàn)刪除功能的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
在使用layui的多圖上傳時發(fā)現(xiàn)沒有刪除功能

在網(wǎng)上搜索解決辦法時有的感覺太復雜有的不符合自己所需要的所以就自己動手

下面附上代碼
HTML:
<div class="layui-upload">
<button type="button" class="layui-btn" id="test2">多圖片上傳</button>
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;width: 88%">
預覽圖:
<div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list">
</div>
</blockquote>
</div>
CSS:
<style type="text/css">
.uploader-list {
margin-left: -15px;
}
.uploader-list .info {
position: relative;
margin-top: -25px;
background-color: black;
color: white;
filter: alpha(Opacity=80);
-moz-opacity: 0.5;
opacity: 0.5;
width: 100px;
height: 25px;
text-align: center;
display: none;
}
.uploader-list .handle {
position: relative;
background-color: black;
color: white;
filter: alpha(Opacity=80);
-moz-opacity: 0.5;
opacity: 0.5;
width: 100px;
text-align: right;
height: 18px;
margin-bottom: -18px;
display: none;
}
.uploader-list .handle span {
margin-right: 5px;
}
.uploader-list .handle span:hover {
cursor: pointer;
}
.uploader-list .file-iteme {
margin: 12px 0 0 15px;
padding: 1px;
float: left;
}
</style>
js:
upload.render({
elem: '#test2'
,url: ''
,multiple: true
,before: function(obj){
layer.msg('圖片上傳中...', {
icon: 16,
shade: 0.01,
time: 0
})
}
,done: function(res){
layer.close(layer.msg());//關(guān)閉上傳提示窗口
//上傳完畢
$('#uploader-list').append(
'<div id="" class="file-iteme">' +
'<div class="handle"><span class="glyphicon glyphicon-trash"></span></div>' +
'<img style="width: 100px;height: 100px;" src=https://'+ res.href +'>' +
'<div class="info">' + res.name + '</div>' +
'</div>'
);
}
});
$(document).on("mouseenter mouseleave", ".file-iteme", function(event){
if(event.type === "mouseenter"){
//鼠標懸浮
$(this).children(".info").fadeIn("fast");
$(this).children(".handle").fadeIn("fast");
}else if(event.type === "mouseleave") {
//鼠標離開
$(this).children(".info").hide();
$(this).children(".handle").hide();
}
});
// 刪除圖片
$(document).on("click", ".file-iteme .handle", function(event){
$(this).parent().remove();
});
以上這篇layui多圖上傳實現(xiàn)刪除功能的例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
javascript+xml技術(shù)實現(xiàn)分頁瀏覽
基于web的技術(shù)中,分頁是一個老的不能再老的,但大家津津樂道的問題,隨著xml技術(shù)的日漸應用,把xml應用到分頁當中,也是一種可能,當然網(wǎng)上的教程很多,當我都是看得稀里糊涂,索性自己寫一個,與大家分享、指正。2008-07-07
JavaScript實現(xiàn)模態(tài)框拖拽效果
這篇文章主要介紹了通過JavaScript實現(xiàn)模態(tài)框拖拽的效果,以及鼠標松開,可以停止拖動模態(tài)框移動等功能,感興趣的小伙伴可以了解一下2021-12-12
JavaScript前端巧妙實現(xiàn)數(shù)據(jù)實時更新詳解
作為開發(fā)者,我們常面對復雜的開發(fā)環(huán)境,要應對即時通訊與數(shù)據(jù)實時更新的問題,那么該如何精準高效實現(xiàn)這些功能呢,下面小編就來和大家簡單講講2025-03-03
詳解設置Webstorm 利用babel將ES6自動轉(zhuǎn)碼成ES5
這篇文章主要介紹了詳解設置Webstorm 利用babel將ES6自動轉(zhuǎn)碼成ES5,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12
JavaScript中concat復制數(shù)組方法淺析
在本篇文章里小編給大家總結(jié)了關(guān)于JavaScript中concat復制數(shù)組方法知識點,有需要的朋友們可以學習下。2019-01-01

