点击弹窗按钮后如何关闭弹窗?
MOOD 2016-05-16 01:29:47 来源:http://www.datouwang.com/jiaoben/109.html
/*
* ClassM
* Copyright (c) 2013 Class http://gaoge.name
* E-Mail:g@gaoge.name
* Date: 2013-08
*/
var fid = parseInt('$_G[fid]');
var tid = parseInt('$_G[tid]');
//alert("jquery.classm.js");
(function(jq){
jq.classM = function(options){
//alert("ClassM");
var defaults = { }
var options = jq.extend(defaults, options);//
jq(document).each(function(){//jq()
jq("body").bind('contextmenu',function(e){ //1.屏蔽右键
//alert("contextmenu");
return false;
});
jq("[id*='-d']").mousedown(function(e){ //mousedown/oncontextmenu //按下
//clearInterval(TimerID);
//alert("mousedown");
show(e);//显示菜单
})
jq("body").mouseup(function(){//弹起
clearTimeout(setM)
})
jq(document).scroll(function(){//滚动
removeClassM()
})
})
//菜单显示内容
function show(e){
var e = e || window.event;//兼容火狐和IE
if(e.button == "2"){ //
//alert("e.button:"+e.button);
var DJID = e.target.id || e.srcElement.id //id要小写
if( DJID=="" ){ return false; }
//alert("DJID:"+DJID);
var aa = "forum.php?mod=post&action=reply&fid="+fid+"&tid="+tid;//+"&reppost="+pid+"&extra="+extra+"&page="+page;
//var aa = "123";
//alert("aa"+aa);
options = {//"="
content:"<div class='classM'>" +
"<a href='"+aa+"&do=add&DJID="+DJID+"&VOTE=1' onClick='showWindow("reply", this.href)' class='M_1'>赞同</a>" +
"<a href='"+aa+"&do=subtract&DJID="+DJID+"&VOTE=2' onclick='showWindow("reply", this.href)' class='M_2'>反对</a>" +
"<a href='"+aa+"&do=translate&DJID="+DJID+"&VOTE=9' onclick='showWindow("reply", this.href)' class='M_3'>翻译</a>" +
"<a href='"+aa+"&do=think&DJID="+DJID+"VOTE=8' onclick='jq.m();showWindow("reply", this.href);' class='M_4'>感想</a></div>",
width:388,//this Tip Width
height:93,//this Tip Height
background:"images/bg.png",//this Tip Background
time:1,//show Time
animateTime:1//animate
}
setM = setTimeout(mouseD,options.time);
winW = jq(window).width();
winH = jq(document).height();
var positionX = e.originalEvent.x || e.originalEvent.layerX || 0; //兼容火狐和IE
winX = ((positionX+options.width/2+20)>winW)?winW-20:positionX-options.width/2;//向右对齐
winX = (winX+20>0)?winX:20;//向左对齐
if ( winW-winX < options.width ) { winX = winX-options.width }
winY = e.originalEvent.y || e.originalEvent.layerY || 0; //兼容火狐和IE
winScroll = jq(document).scrollTop()
winY = (window.event)?winY+winScroll-10:WinY-10;//兼容火狐和IE
event.returnValue = false;
}
}
mouseD = function mouseD(){
jq("body").append("<div class='classMBg' style='position:absolute;top:0;left:0;background:#fff;width:100%;height:"+winH+"px;z-index:9999;'></div>");
jq(".classMBg").css("opacity","0").click(function(){removeClassM();});
jq(".classMBox").remove();
jq("body").append(
" <div class='classMBox' style='position:absolute;top:"+winY+"px;left:"+winX+"px;z-index:99999;display:none;width:0;text-align:center'>"
+ "<div style='width:"+options.width+"px;height:"+options.height+"px;background:url("+options.background+");'>"
+ options.content
+ "</div></div>");
jq(".classMBox a").focus(function(){ jq(this).blur() })
jq(".classMBox a").hover(function(){ jq(this).fadeTo("slow",0.5) },function(){ jq(this).fadeTo("slow",1) })
jq(".classMBox").show().animate({width:options.width+"px"},options.animateTime)
jq(document).keydown(function(event){
if ( event.keyCode == 27 ) { removeClassM() }//27:esc
})
//alert("mD");
}
function removeClassM(){
jq(".classMBox").animate({width:"0"},options.animateTime,function(){ jq(".classMBg,.classMBox").remove() })
}
}
//
})(jQuery);
这是个右键弹窗菜单,源码修改自网络。
其中:
"<a href='"+aa+"&do=think&DJID="+DJID+"VOTE=8' onclick='jq.m();showWindow("reply", this.href);' class='M_4'>感想</a></div>",
想在onclick()中调用removeClassM()来关闭右键弹窗,如何写?
目的就是点击弹窗上按钮后关闭弹窗