같은 position에 있는 (꼭 같이 있을 필요는 되지만) 레이어를 투명도를 이용하여 부드럽게 교차시켜 줍니다.

소스가 상당히 노가다적입니다;

또 나름대로 주석을 달아놓긴 했는데, 말을 이해하기는 힘드실겁니다-_-;;


고쳐야 할 부분 알려주시면 감사하고, 필요하신 분들은 유용하게 쓰시기 바랍니다~

<html> <head> <script type="text/javascript">if (!window.T) { window.T = {} } window.T.config = {"TOP_SSL_URL":"https://www.tistory.com","PREVIEW":false,"ROLE":"guest","PREV_PAGE":"","NEXT_PAGE":"","BLOG":{"id":142411,"name":"qtvirus","title":"QT그리고&middot;&middot;&middot;","isDormancy":true,"nickName":"Redvirus","status":"open","profileStatus":"normal"},"NEED_COMMENT_LOGIN":false,"COMMENT_LOGIN_CONFIRM_MESSAGE":"","LOGIN_URL":"https://www.tistory.com/auth/login/?redirectUrl=http://qtvirus.tistory.com/tag/%25EB%25A0%2588%25EC%259D%25B4%25EC%2596%25B4","DEFAULT_URL":"https://qtvirus.tistory.com","USER":{"name":null,"homepage":null,"id":0,"profileImage":null},"SUBSCRIPTION":{"status":"none","isConnected":false,"isPending":false,"isWait":false,"isProcessing":false,"isNone":true},"IS_LOGIN":false,"HAS_BLOG":false,"IS_SUPPORT":false,"TOP_URL":"http://www.tistory.com","JOIN_URL":"https://www.tistory.com/member/join","ROLE_GROUP":"visitor"}; window.T.entryInfo = null; window.appInfo = {"domain":"tistory.com","topUrl":"https://www.tistory.com","loginUrl":"https://www.tistory.com/auth/login","logoutUrl":"https://www.tistory.com/auth/logout"}; window.initData = {}; window.TistoryBlog = { basePath: "", url: "https://qtvirus.tistory.com", tistoryUrl: "https://qtvirus.tistory.com", manageUrl: "https://qtvirus.tistory.com/manage", token: "EXVGr5Chcajjp8ozSE1l7bidlGmHejXzoNWLY88YyegUWzAcI8m9LVdcLNmBiFuj" }; var servicePath = ""; var blogURL = "";</script> <title>반투명하게 레이어 교차하기</title> <pre class="scripts" lanugage="JavaScript"> var name = "layer"; //레이어의 이름. var space = 1; //반투명 처리 간격. var time1 = 0.1; //반투명도를 한간격 변경할 시간입니다. (초 단위) var time2 = 2; //교차가 완료된 후 대기할 시간입니다. (초 단위) var tran=1; //반투명도를 계산할 변수. (수정하는 것 아님) var tranlr=1; //레이어1의 번호. (수정하는 것 아님) function transparent() { if(!document.getElementById(name+"1")) return; //레이어1이 없다면 그냥 함수를 끝낸다. var tranlr2=tranlr+1; //교차할 그 다음의 레이어 (레이어2) if(!document.getElementById(name+tranlr2)) tranlr2=1; //레이어2가 없다면 처음레이어로 돌아간다. var preview = document.getElementById(name+tranlr); var preview2 = document.getElementById(name+tranlr2); if(preview2.style.opacity!="1") { //레이어2가 아직 반투명할 경우 preview2.style.display="block"; /* 여기부터는 Firefox의 방식 - style의 opacity가 1이면 불투명, 0이면 투명 */ var a=Math.round((tran - space*0.1)*10)/10; //레이어1의 변경될 투명도 var b=Math.round(Math.abs(a-1)*10)/10; //레이어2의 변경될 투명도. a에서 1을 뺀다음, 절대값. preview.style.opacity=a; preview2.style.opacity=b; /* 여기부터는 IE의 방식 - filter:alpha가 opacity=100이면 불투명, 0이면 투명 */ a=tran*100 - space*10; //레이어1의 변경될 투명도 b=Math.abs(a - 100); //레이어2의 변경될 투명도. a에서 100을 뺀다음, 절대값. preview.style.filter="alpha(opacity="+a+")"; preview2.style.filter="alpha(opacity="+b+")"; tran=tran - space*0.1; setTimeout("transparent();", time1*1000); } else { //레이어2가 완전히 보일 경우 preview.style.display="none"; tranlr++; if(!document.getElementById(name+tranlr)) tranlr=1; tran=1; setTimeout("transparent();", time2*1000); } } </pre> <style type="text/css">.another_category { border: 1px solid #E5E5E5; padding: 10px 10px 5px; margin: 10px 0; clear: both; } .another_category h4 { font-size: 12px !important; margin: 0 !important; border-bottom: 1px solid #E5E5E5 !important; padding: 2px 0 6px !important; } .another_category h4 a { font-weight: bold !important; } .another_category table { table-layout: fixed; border-collapse: collapse; width: 100% !important; margin-top: 10px !important; } * html .another_category table { width: auto !important; } *:first-child + html .another_category table { width: auto !important; } .another_category th, .another_category td { padding: 0 0 4px !important; } .another_category th { text-align: left; font-size: 12px !important; font-weight: normal; word-break: break-all; overflow: hidden; line-height: 1.5; } .another_category td { text-align: right; width: 80px; font-size: 11px; } .another_category th a { font-weight: normal; text-decoration: none; border: none !important; } .another_category th a.current { font-weight: bold; text-decoration: none !important; border-bottom: 1px solid !important; } .another_category th span { font-weight: normal; text-decoration: none; font: 10px Tahoma, Sans-serif; border: none !important; } .another_category_color_gray, .another_category_color_gray h4 { border-color: #E5E5E5 !important; } .another_category_color_gray * { color: #909090 !important; } .another_category_color_gray th a.current { border-color: #909090 !important; } .another_category_color_gray h4, .another_category_color_gray h4 a { color: #737373 !important; } .another_category_color_red, .another_category_color_red h4 { border-color: #F6D4D3 !important; } .another_category_color_red * { color: #E86869 !important; } .another_category_color_red th a.current { border-color: #E86869 !important; } .another_category_color_red h4, .another_category_color_red h4 a { color: #ED0908 !important; } .another_category_color_green, .another_category_color_green h4 { border-color: #CCE7C8 !important; } .another_category_color_green * { color: #64C05B !important; } .another_category_color_green th a.current { border-color: #64C05B !important; } .another_category_color_green h4, .another_category_color_green h4 a { color: #3EA731 !important; } .another_category_color_blue, .another_category_color_blue h4 { border-color: #C8DAF2 !important; } .another_category_color_blue * { color: #477FD6 !important; } .another_category_color_blue th a.current { border-color: #477FD6 !important; } .another_category_color_blue h4, .another_category_color_blue h4 a { color: #1960CA !important; } .another_category_color_violet, .another_category_color_violet h4 { border-color: #E1CEEC !important; } .another_category_color_violet * { color: #9D64C5 !important; } .another_category_color_violet th a.current { border-color: #9D64C5 !important; } .another_category_color_violet h4, .another_category_color_violet h4 a { color: #7E2CB5 !important; } </style> <link rel="stylesheet" type="text/css" href="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/style/revenue.css"/> <link rel="canonical" href="https://qtvirus.tistory.com"/> <!-- BEGIN STRUCTURED_DATA --> <script type="application/ld+json"> {"@context":"http://schema.org","@type":"WebSite","url":"/","potentialAction":{"@type":"SearchAction","target":"/search/{search_term_string}","query-input":"required name=search_term_string"}} </script> <!-- END STRUCTURED_DATA --> <link rel="stylesheet" type="text/css" href="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/style/dialog.css"/> <link rel="stylesheet" type="text/css" href="//t1.daumcdn.net/tistory_admin/www/style/top/font.css"/> <link rel="stylesheet" type="text/css" href="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/style/postBtn.css"/> <link rel="stylesheet" type="text/css" href="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/style/comment.css"/> <link rel="stylesheet" type="text/css" href="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/style/tistory.css"/> <script type="text/javascript" src="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/script/common.js"></script> <script type="text/javascript" src="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/script/comment.js" defer=""></script> </head> <body> <div id="layer1" style="display:block;position:absolute;">안녕하세요. 미니위니 여러분!</div> <div id="layer2" style="display:none;position:absolute;">반가워요~</div> <div id="layer3" style="display:none;position:absolute;">사랑합니다!</div> <div id="layer4" style="display:none;position:absolute;">알라뷰~♡</div> <pre class="scripts" language="JavaScript"> //레이어 교차 함수 시작! document.getElementById(name+"1").style.opacity=1; document.getElementById(name+"1").style.filter="alpha(opacity=100)"; setTimeout("transparent();",time2*1000); </pre> <script type="text/javascript">(function($) { $(document).ready(function() { lightbox.options.fadeDuration = 200; lightbox.options.resizeDuration = 200; lightbox.options.wrapAround = false; lightbox.options.albumLabel = "%1 / %2"; }) })(tjQuery);</script> <div style="margin:0; padding:0; border:none; background:none; float:none; clear:none; z-index:0"></div> <script type="text/javascript" src="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/script/common.js"></script> <script type="text/javascript">window.roosevelt_params_queue = window.roosevelt_params_queue || [{channel_id: 'dk', channel_label: '{tistory}'}]</script> <script type="text/javascript" src="//t1.daumcdn.net/midas/rt/dk_bt/roosevelt_dk_bt.js" async="async"></script> <script type="text/javascript" src="https://tistory1.daumcdn.net/tistory_admin/userblog/tistory-717c7b1234a0a46519d1483dc3db06322985d92c/static/script/menubar.min.js"></script> <script>window.tiara = {"svcDomain":"user.tistory.com","section":"기타","trackPage":"글뷰_보기","page":"글뷰","key":"142411","customProps":{"userId":"0","blogId":"142411","entryId":"null","role":"guest","trackPage":"글뷰_보기","filterTarget":false},"entry":null,"kakaoAppKey":"3e6ddd834b023f24221217e370daed18","appUserId":"null"}</script> <script type="module" src="https://t1.daumcdn.net/tistory_admin/frontend/tiara/v1.0.0/index.js"></script> <script src="https://t1.daumcdn.net/tistory_admin/frontend/tiara/v1.0.0/polyfills-legacy.min.js" nomodule="true" defer="true"></script> <script src="https://t1.daumcdn.net/tistory_admin/frontend/tiara/v1.0.0/index-legacy.js" nomodule="true" defer="true"></script> </body> </html>
Posted by 알 수 없는 사용자
,
서브메뉴에서 창의 크기에 따라 레이어의 위치가 주메뉴와 일치하지 않는 것을 해결하는
방법을 찾으시는 분이 많으신 것 같아 방법을 알려드리지요..
방법은 여러가지가 있지요...
주메뉴를 레이어에 넣어서 주메뉴 레이어를 화면 중앙에 오게 하고 나머지 서브메뉴를
주메뉴 레이어에의 상대적 위치에 따라 위치를 결정하는 방법..
아니면 일일히 서브레이어의 위치를 상대적으로 지정하는 방법 등등..

이중에 간단히 두번째 일일히 지정하는 방법을 좀더 간단히 하는 방법을 알려드리면...

<style>
#Layer
{
position:absolute;
left:expression!!((document.body.clientWidth-this.style.width)/2-this.getAttribute("pos"));
}
</style>

일단 스타일 시트에서 expression!!메쏘드로 자바스크립트를 이용하여 레이어의 좌측 위치를
body태그, 즉 실제문서가 표시된 부분 만큼의 너비를 이용하여 화면 중앙의 위치를 구합니다.
보이는 화면을 1/2하면 중앙이 되겠지요..

(document.body.clientWidth-this.style.width)/2
위와 같이 하는 이유는 레이어의 너비를 화면 크기에서 빼주어야 레이어 좌측이 중앙으로 부터
레이어 너비의 반만큼 왼쪽으로 더 이동되어 화면 정중앙에 오기때문이죠..

그리고 this.getAttribute("pos")는 pos라는 사용자 속성 값을 읽어 오는 겁니다.
레이어마다 따로 아이디를 부여할 필요없이 하나의 아이디로 하려고 사용하는 게지요..

그럼 실제 레이어에 적용해보지요..

아래처럼 그냥 레이어를 만드시고 id를 모두 동일하게 Layer로 줍니다.
pos는 위에서 말씀드린 사용자 속성입니다.
화면중앙에서 +값이면 왼쪽으로 이동시킬 픽셀값이고 -는 오른쪽으로 이동시킬 픽셀값이 되는 것이지요.

그럼 확인한번 해보세요..


<div id=Layer pos=60>
메뉴1
</div>

<div id=Layer pos=-30>
메뉴2
</div>

<div id=Layer pos=0>
메뉴3
</div>

<div id=Layer pos=100>
메뉴4
</div>

머 이밖에 behavior!!를 이용하는 방법(클래스 지정만으로 서브메뉴 구현가능)도 있는데..
초보자에게는 어려우니 위에 방법을 써보시고 좀더 공부하시고 behavior!!를 이용한 방법을
사용해 보시는 것도 좋을 듯 하네요..

단, 위 방법은 id가 모두 동일하므로 mouseover/out이벤트 핸들러를 적용할때는 레이어를 배열로 지정하셔서 사용하셔야 합니다.
Posted by 알 수 없는 사용자
,