效果如下:
css文件delcss.css
代码如下:
复制代码 代码如下:
*{ margin:0; padding:0;}
#div1{ width:300px; height:100px; border-radius:10px; background:#f60; box-shadow:5px 5px 10px #ccc; position:absolute; left:50%; margin-left:-150px; z-index:2; opacity:0; filter:alpha(opacity:0); display:none;}
#div1 h3{ height:20px; background:#60f;}
#overlay{ width:100%; height:100%; background:#ccc; position:absolute; left:0; top:0; opacity:0; z-index:1; display:none;}
#closeconfirm{ width:80px; height:20px; line-height:20px; background:#ccc; border-radius:5px; display:block; text-decoration:none; color:#000; text-align:center; position:absolute; bottom:10px; right:10px;}
#trueconfirm{width:80px; height:20px; line-height:20px; background:#ccc; border-radius:5px; display:block; text-decoration:none; color:#000; text-align:center; position:absolute; bottom:10px; right:100px;}
#confirmcon{ text-align:center; color:#ccc; height:40px; line-height:40px;}
js文件confirmpop.js代码如下:
复制代码 代码如下:
function confirmpop(delobj,confirmmain,overlay,binktitle,closeconfirm,trueconfirm){
this.odelobj=document.getelementbyid(delobj);
this.odiv=document.getelementbyid(confirmmain);
this.ooverlay=document.getelementbyid(overlay);
this.otitle=document.getelementbyid(binktitle);
this.ocloseconfirm=document.getelementbyid(closeconfirm);
this.otrueconfirm=document.getelementbyid(trueconfirm);
this.oconstart=0;
this.oconitarget=0;
this.init();
}
confirmpop.prototype={
init:function(){
this.oconstart=parseint((document.documentelement.clientheight-this.odiv.offsetheight)/2-100);
this.oconitarget=parseint((document.documentelement.clientheight-this.odiv.offsetheight)/2-70);
this.odiv.style.top=this.oconstart+'px';
document.title=this.oconstart+', '+this.oconitarget;
var _this=this;
this.odelobj.onclick=function(){
_this.confirmshow();
}
this.ooverlay.onclick=function(){
_this.titlebink();
}
this.ocloseconfirm.onclick=this.otrueconfirm.onclick=function(){
_this.confirmhide();
}
},
confirmshow:function(){
this.ooverlay.style.display='block';
this.odiv.style.display='block';
strivemove(this.ooverlay,{ opacity:30});
strivemove(this.odiv,{top:this.oconitarget, opacity:100})
},
titlebink:function(){
var _this=this;
var ilighttimer=null;
var i=0;
ilighttimer=setinterval(function(){
if(i%2){
_this.otitle.style.background='#60f';
}else{
_this.otitle.style.background='#ccc';
}
i++;
if(i>5){
clearinterval(ilighttimer);
}
},50)
},
confirmhide:function(){
strivemove(this.ooverlay,{opacity:0});
this.ooverlay.style.display='none';
strivemove(this.odiv,{top:this.oconstart, opacity:0});
}
}
function strivemove(obj,json,fn){clearinterval(obj.itimer);obj.itimer=setinterval(function(){var bstop=true;for(var attr in json){var icur=0;if(attr=='opacity'){icur=math.round(parsefloat(getstyle(obj,attr))*100);}else{icur=parseint(getstyle(obj,attr));}var ispeed=(json[attr]-icur)/8;ispeed=ispeed>0?math.ceil(ispeed):math.floor(ispeed);if(attr=='opacity'){obj.style.filter='alpha(opacity:'+(icur+ispeed)+')';obj.style.opacity=(icur+ispeed)/100;}else{obj.style[attr]=icur+ispeed+'px';}if(icur!==json[attr]){bstop=false;}}if(bstop){clearinterval(obj.itimer);if(fn){fn();}}},30)}function getstyle(obj,attr){return obj.currentstyle?obj.currentstyle[attr]:getcomputedstyle(obj,false)[attr];}
使用方法1.引入文件
复制代码 代码如下:
2.调用方法
复制代码 代码如下:
3.做好准备工作
复制代码 代码如下:
您确定要进行删除操作么?
确定
取消
这段代码是提供空间的,自己写的div代码。其中确定框中的a标签中,可以把删除的地址填入其中。点击确定时,就跳转到删除的页面方法中了。这段代码可以放入任何位置。不占空间。作者很犀利。
4.导火线,触发器
复制代码 代码如下:
将删除图标加上id=btn,这样就会触发删除效果了。如果想修改样式,可以到css中进行修改,调整。
小结:这样的js删除就比浏览器自带的弹出框美观一些了。作者用短短3k的js就写出这种效果,真心厉害。
ps,我只是拿来的。
缺点,只能针对一个内容,进行删除。因为所有的都是针对id的,单一化了。