심플한 라이트박스 효과 (이미지, 아이프렘, html 지원) - 수정됨
페이지 정보
작성자 서방님 댓글 0건 조회 126회 작성일 07-02-03 14:23본문
본론:
다들 라이트박스 아시죠?
이미지 클릭하면 주변배경이 반투명으로 어두워지면서...
가운데 이미지가 나와주는....
그넘이 몇차례 진화하더니...스르르륵 거리고..멋쪄지고...
그것들을 응용해서 아이프렘이나..html 을 표시해주는등의 물건들도 나오고...
그런데 갈수록..좋아질수록... 무거워지더란 말이죠..
그래서 단순하게 비슷한 효과만 내는 스크립트를 짜봤습니다.
속도좋고...심플하고 뭐 그럭저럭 쓸만한것 같습니다.ㅋㅋ
결론:
소스는 미리보기 해보시면 다 알아보실겁니다...
기존 페이지에 넣어서 사용하시는 방법은....
우선 위 소스에서 style 과 script 의 내용이 모두 head 안에 들어가야 하구요...
그리고 <body> 바로 밑에 있는 3개의 div 가 필수적으로 들어가주면 설치 끝입니다.
나머진...위 미리보기에 나온 사용법을 응용해서 링크 잘 만들어서 쓰시면 되는거죠~
홧팅!
추가1:
2007/01/30 오후 4시45분경... 이미지 밑에 캡션넣을수 있게 살짝 수정했습니다.~^^
추가2: 응용에 대한 설명인데요....
눌려질 이미지가 아이프레임내부에 있을경우... 본 효과에 사용된 스크립트와 스타일와 필수div 3개는 아이프레임의 바깥쪽에 설치해두고 아이프레임 내부에서 바깥페이지의 스크립트를 parent.SLB_show('이미지주소','image',false); 로 호출해주면 아이프레임내부에만 생기는 투명배경과 이미지를 아이프렘 바깥의 페이지 전체에 보여주게 할수 있겠습니다.
<html>
<head>
<title>심플 라이트박스 효과</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<style type="text/css">
html { width:100%; height:100%; }
body { width:100%; height:100%; margin: 0px; padding: 0px; font-size:9pt; }
.SLB_center { cursor:pointer; visibility:hidden; border: solid 4px #000000; }
.SLB_close { cursor: pointer; display:none; font-family: verdana,tahoma; font-size: 9pt; background-color:#000000; color: #ffffff; padding-bottom: 4px; }
.SLB_caption { cursor: pointer; display:none; font-family: verdana,tahoma; font-size: 9pt; background-color:#000000; color: #ffffff; padding-bottom: 4px; }
#SLB_loading { cursor: pointer; display:none; z-index: 99998; position:absolute; font-family: verdana,tahoma; font-size: 9pt; background-color:#000000; color: #ffffff; padding: 3px 0px 4px 0px; border: solid 2px #cfcfcf; }
</style>
<script language="javascript" type="text/javascript">
// 심플 라이트박스 효과 by 알릭 (2007/01/30)
// http://www.alik.info
function SLB_show(url, type)
{
var a = document.getElementById('SLB_film');
var b = document.getElementById('SLB_content');
var c = document.getElementById('SLB_loading');
if(url) {
a.style.top = 0;
a.style.left = 0;
a.style.display = "";
a.style.height = document.body.scrollHeight + 'px';
document.getElementById('SLB_loading').style.display = "block";
SLB_setCenter(c,true);
if(type == 'image') {
b.innerHTML="<img src=" + url + " class='SLB_center' onload='SLB_setCenter(this);' />";
if(arguments[2]) a.onclick = function () { SLB_show() };
if(arguments[3]) b.innerHTML += "<div class='SLB_caption'>"+ arguments[3] +"</div>";;
} else if (type == 'iframe') {
b.innerHTML="<iframe src=" + url + " width="+ arguments[2] +" height="+ arguments[3] +" class='SLB_center' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0' onload='SLB_setCenter(this);' /></iframe>";
if(arguments[4]) {
b.innerHTML += "<div class='SLB_close' onclick='SLB_show();' title='닫기'>close</div>";
}
b.onclick = ''; b.firstChild.style.cursor = 'default';
} else if (type='html'){
b.innerHTML = url;
SLB_setCenter(b.firstChild);
if(arguments[2]) b.onclick = '';
}
} else {
a.onclick = '';
a.style.display = "none";
b.innerHTML = "";
b.onclick = function () { SLB_show() };
c.style.display = "none";
}
}
function SLB_setCenter(obj) {
if (obj) {
var h = window.innerHeight || self.innerHeight || document.body.clientHeight;
var w = window.innerWidth || self.innerWidth || document.body.clientWidth;
var l = (document.body.scrollLeft + ((w-(obj.width||parseInt(obj.style.width)||obj.offsetWidth))/2)) ;
var t = (document.body.scrollTop + ((h-(obj.height||parseInt(obj.style.height)||obj.offsetHeight))/2)) ;
if((obj.width||parseInt(obj.style.width)||obj.offsetWidth) >= w) l = 0;
if((obj.height||parseInt(obj.style.height)||obj.offsetHeight) >= h) t = 0;
document.getElementById('SLB_content').style.left = l + "px";
document.getElementById('SLB_content').style.top = t + "px";
obj.style.visibility = 'visible';
if(obj.nextSibling && (obj.nextSibling.className == 'SLB_close' || obj.nextSibling.className == 'SLB_caption')) {
obj.nextSibling.style.display = 'block';
}
if(!arguments[1]) {
document.getElementById('SLB_loading').style.display = "none";
} else {
obj.style.left = l + "px";
obj.style.top = t + "px";
}
}
}
var prevOnScroll = window.onscroll;
window.onscroll = function () {
if(prevOnScroll != undefined) prevOnScroll();
document.getElementById('SLB_film').style.height = document.body.scrollHeight + 'px';
document.getElementById('SLB_film').style.width = document.body.scrollWidth + 'px';
SLB_setCenter(document.getElementById('SLB_content').firstChild);
}
var prevOnResize = window.onresize;
window.onresize = function () {
if(prevOnResize != undefined) prevOnResize();
document.getElementById('SLB_film').style.height = document.body.offsetHeight + 'px';
document.getElementById('SLB_film').style.width = document.body.offsetWidth + 'px';
SLB_setCenter(document.getElementById('SLB_content').firstChild);
}
</script>
</head>
<body>
<div id="SLB_film" style="z-index: 99997; position:absolute; display:none; width:100%; height:100%; background-color:#000000; filter:Alpha(opacity=60); opacity:0.6; -moz-opacity:0.6;"></div>
<div id="SLB_content" onclick="SLB_show();" align="center" style="z-index: 99999; position:absolute;"></div>
<div id="SLB_loading" onclick="SLB_show();" title="로딩중...클릭시 취소"> Loading... </div>
<div style="margin:10px 0px 0px 20px;">
<a onclick="SLB_show('http://i.blog.empas.com/frozen108/28257327_365x396.jpg','image',true);" style='cursor:pointer; border-bottom:2px solid blue; line-height:2;'>이미지 띄우기</a><br />
실행코드: SLB_show('http://i.blog.empas.com/frozen108/28257327_365x396.jpg','image',true);<br />
설명: SLB_show('이미지주소', 'image', 반투명배경클릭시닫기?(true or false));<br /><br />
<a onclick="SLB_show('http://i.blog.empas.com/frozen108/28257327_365x396.jpg','image',false, '오~이쁘당!<i>김태희 ^^</i>');" style='cursor:pointer; border-bottom:2px solid blue; line-height:2;'>이미지 띄우기 - 캡션과 함께</a><br />
실행코드: SLB_show('http://i.blog.empas.com/frozen108/28257327_365x396.jpg','image',false, '오~이쁘당!<i>김태희 ^^</i>');<br />
설명: SLB_show('이미지주소', 'image', 반투명배경클릭시닫기?(true or false), '캡션내용');<br /><br />
<a onclick="SLB_show('http://www.yahoo.com','iframe', 600, 400, true);" style='cursor:pointer; border-bottom:2px solid blue; line-height:2;'>아이프레임 띄우기</a><br />
SLB_show('http://www.yahoo.com','iframe', 600, 400, true);<br />
SLB_show('아이프래임 src', 'iframe', 가로크기, 세로크기, 아이프렘하단에 닫기버튼표시?(true or false));<br /><br />
<a onclick="SLB_show('<div style='border:2px solid red; width:200px; height:100px; background-color:yellow'>하하하하하<br />ㅋㅋㅋㅋ</div>','html');" style='cursor:pointer; border-bottom:2px solid blue; line-height:2;'>html 띄우기1</a><br />
SLB_show('<div style='border:2px solid red; width:200px; height:100px; background-color:yellow'>하하하하하<br />ㅋㅋㅋㅋ</div>','html');<br />
SLB_show('html 소스', 'html', 중앙 내용클릭해도 안닫히기?(true or false));
<br /><br />
<a onclick="SLB_show('<div id='asd'><div>TABLE</div><table border=1 bgcolor=#ffffff><tr><td>다른곳은</td><td>클릭해도</td></tr><tr><td>안닫힘</td><td onclick='SLB_show();' bgcolor='red'>닫기는여기<br />onclick='SLB_show();'</td></tr></table></div>','html', true);" style='cursor:pointer; border-bottom:2px solid blue; line-height:2;'>html 띄우기2</a>
<br />
SLB_show('<div id='asd'><div>TABLE</div><table border=1 bgcolor=#ffffff><tr><td>다른곳은</td><td>클릭해도</td></tr><tr><td>안닫힘</td><td onclick='SLB_show();' bgcolor='red'>닫기는여기<br />onclick='SLB_show();'</td></tr></table></div>','html', true);<br /><br /><br />
* 닫기는 SLB_show(); 를 호출하면 닫힘<br />
* 아이프래임의 내부에 있는 문서에서 닫을려면 parent.SLB_show(); 로 닫을수 있음.<br />
* 로딩중 표시를 클릭하면 로딩 최소됨<br />
* 반투명배경의 투명도 및 색상은 <br />
<div id="SLB_film" style="z-index: 99997; position:absolute; display:none; width:100%; height:100%; <font style="BACKGROUND-COLOR: #ffff00" color=#fe1100>background-color:#000000; filter:Alpha(opacity=60); opacity:0.6; -moz-opacity:0.6;</font>"></div>
<br />에서 수정가능
</div>
</body>
</html>
출처 : 미니위니
댓글목록
등록된 댓글이 없습니다.