마우스오버 드롭다운 메뉴
마우스오버 드롭다운 메뉴로 사용시에는 여러가지 문제로 -_- 다음 변수와 함수를 추가 후 사용해야 하며, 이벤트를 적용하는
엘리먼트의 onmouseout이벤트에는 layerclose('제어할 레이어 아이디')를 지정하고, 타겟 레이어 자체에
onmouseover="layerwaitforclose('제어할 레이어의 아이디')"
onmouseout="layerclose('제어할 레이어의 아이디')" 이벤트를 지정.
var layerclosetimer=null;
function layerclose(layerid){
layerclosetimer=setTimeout("layer('"+layerid+"')",100);
}
function layerwaitforclose(layerid){
clearTimeout(layerclosetimer);
}
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>레이어 컨트롤 샘플3</title>
- <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
- <meta http-equiv="imagetoolbar" content="no">
- <style type="text/css">
- body{
- font-family:tahoma;
- font-size:0.74em;
- color:#000;
- margin:0;
- padding:0;
- }
-
- #dropdown{
- position:absolute;
- left:50%;
- top:10px;
- width:100px;
- line-height:1.3em;
- margin-left:-55px;
- padding:1px 5px;
- border:1px solid #BBB;
- background:#FFF;
- cursor:pointer;
- }
- #dropdownlayer{
- position:absolute;
- width:106px;
- line-height:1.3em;
- padding:2px;
- border:1px solid #BBB;
- background:#FFF;
- display:none;
- }
- #dropdownlayer a{
- padding:1px 3px;
- display:block;
- }
- #dropdownlayer a:hover{
- background:#EEE;
- }
- </style>
- <script type="text/javascript">
- var layerclosetimer=null;
- function layerclose(layerid){
- layerclosetimer=setTimeout("layer('"+layerid+"')",100);
- }
- function layerwaitforclose(layerid){
- clearTimeout(layerclosetimer);
- }
- function layer(layerid,target,xpos,ypos,isoverevent){
-
- // 위치 제어가 가능한 레이어 컨트롤.
- // http://www.psyonline.kr
-
- try{clearTimeout(layerclosetimer)}catch(error){}
- var obj=document.getElementById(layerid);
- if(!obj.style.display || obj.style.display=='none'){
- var targetinfo=[target.offsetWidth,target.offsetHeight,0,0];
- for(var i=0; i<1; i++){
- targetinfo[2]+=target.offsetLeft;
- targetinfo[3]+=target.offsetTop;
- target=target.offsetParent;
- if(target.tagName.toLowerCase()!='body' && target.tagName.toLowerCase()!='html') i--;
- }
- obj.style.display='block';
- var objinfo=[obj.offsetWidth,obj.offsetHeight];
- obj.style.display='none';
- if(xpos || ypos){
- if(xpos){
- if(!isNaN(xpos)) setleft(xpos);
- else{
- var xpospm;
- if(xpospm=xpos.match(/([a-z-]+)(\-|\+)([0-9]+)/)) xpos=xpospm[1];
- if(xpos=='left') setleft(targetinfo[2]-objinfo[0]);
- else if(xpos=='justify-left') setleft(targetinfo[2]);
- else if(xpos=='right') setleft(targetinfo[2]+targetinfo[0]);
- else if(xpos=='justify-right') setleft((targetinfo[2]+targetinfo[0])-objinfo[0]);
- else if(xpos=='center') setleft((targetinfo[2]+(targetinfo[0]/2))-(objinfo[0]/2));
- }
- }
- if(ypos){
- if(!isNaN(ypos)) settop(ypos);
- else{
- var ypospm;
- if(ypospm=ypos.match(/([a-z-]+)(\-|\+)([0-9]+)/)) ypos=ypospm[1];
- if(ypos=='top') settop(targetinfo[3]-objinfo[1]);
- else if(ypos=='justify-top') settop(targetinfo[3]);
- else if(ypos=='bottom') settop(targetinfo[3]+targetinfo[1]);
- else if(ypos=='justify-bottom') settop((targetinfo[3]+targetinfo[1])-objinfo[1]);
- else if(ypos=='middle') settop((targetinfo[3]+(targetinfo[1]/2))-(objinfo[1]/2));
- }
- }
- }else{
- if(xpos===0) setleft(xpos);
- if(ypos===0) settop(ypos);
- }
- obj.style.display='block';
- }else{
- if(!isoverevent) obj.style.display='none';
- }
-
- function setleft(value){
- if(xpospm) value=eval('value'+xpospm[2]+xpospm[3]);
- obj.style.left=value+'px';
- }
-
- function settop(value){
- if(ypospm) value=eval('value'+ypospm[2]+ypospm[3]);
- obj.style.top=value+'px';
- }
-
- }
- </script>
- </head>
-
- <body>
-
- <div id="dropdown" onmouseover="layer('dropdownlayer',this,'justify-left','bottom+2',true)" onmouseout="layerclose('dropdownlayer')">Drop Down</div>
- <div id="dropdownlayer" onmouseover="layerwaitforclose('dropdownlayer')" onmouseout="layerclose('dropdownlayer')">
- <a href="#">Case 1</a>
- <a href="#">Case 2</a>
- </div>
-
- </body>
- </html>