뭐 많은 사람들이 이미 만든것도 있구...
그분들이 몇년동안 쌓아올려놓은걸 하루아침에 제낄 생각은 없습니다만...
천천히 필요한기능을 넣고 필요없는부분은 축소화 시켜나갈 생각입니다.
http://sizkein.textcube.com/entry/jQuery-로-만든-이미지-팝업창
그분들이 몇년동안 쌓아올려놓은걸 하루아침에 제낄 생각은 없습니다만...
천천히 필요한기능을 넣고 필요없는부분은 축소화 시켜나갈 생각입니다.
http://sizkein.textcube.com/entry/jQuery-로-만든-이미지-팝업창
예제 : http://mqoo.com/bbs/images/16
사용법사용법 :
<SCRIPT LANGUAGE="JavaScript">
$(document).ready(function(){
$(".resizeIMG").simplebox({ blind:false , img:true, drag:true });
});
</SCRIPT>
<div id='blank'></div>
다운로드 :
소스코드 : ver0.5ver0.5
/*
version :0.5
만든이 : Sizkein
메일주소 : sizkein@gmail.com
문의사항 : sizkein@gmail.com
저작권 : GPL
공개장소 : developer.mqoo.com
*/
(function ($, window) {
var defaults = {
loading_text:"loading...",
href: false,
src: false,
blind:true,
title : "리사이즈된 이미지입니다.\n원본을 보시려면 클릭해 주세요.",
opacity: 0.6,
backgroundColor : "#000",
fontColor : "#FFF",
img: false, //이것이 true 일때 작동한다.
wheel:true,
iframe : false,
width: 600,
height: 600,
//추가 할 예정인 기능
popup_top_left : "align='center' valign='middle' ", //일단 이름은 대충 정하자
drag:false
},
simplebox = 'simplebox';
function control_box_edit(a, b){
}
function control_box_exit(a, b){
}
function blind(a, options) {
if(a.get(0).tagName=='A') var a = a.children(); //a 클릭이라면 chrome 나 safari,등을 위해서 img 에 블라인드를 걸기위해..
var blind_ = new Array();
if(options.blind){
blind_.top = 0;
blind_.left = 0;
blind_.width = $(document).width();
blind_.height = $(document).height();
}else{
blind_.top = a.offset().top;
blind_.left = a.offset().left;
blind_.width = a.width();
blind_.height = a.height();
}
jQuery("<div/>")
.attr({
id: "index_layer"
})
.css({
position:'absolute',
top: 0,
left: 0,
width: 0,
height: 0,
zIndex: 0
})
.click(function(){$(this).remove()})
.insertAfter("#blank");
jQuery("<div/>")
.attr({
id: "simple_blind"
})
.css({
opacity:options.opacity,
position:'absolute',
top: blind_.top,
left: blind_.left,
width: blind_.width,
height: blind_.height,
zIndex: 9950,
cursor: "pointer",
textAlign: 'center',
color:options.fontColor,
backgroundColor: options.backgroundColor
})
.bind('click',function(){
})
.appendTo("#index_layer");
}
function change_layer(a, options){
//실제 사이즈를 기록해놓는다.
var real_size = new Array();
real_size.width = a.width();
real_size.height = a.height();
var simpleTLWH = new Array();
var img_rateWH = a.width() / a.height(); //이미지 확대축소를 위한 비율작성
var img_rateHW = a.height() / a.width();
//사이즈를 판단한다.
if(a.width()>$(window).width()){
simpleTLWH.width = $(window).width()-50;
simpleTLWH.height = simpleTLWH.width * img_rateHW;
if(simpleTLWH.height >$(window).height()){
simpleTLWH.height = $(window).height()-50;
simpleTLWH.width = simpleTLWH.height * img_rateWH;
}
}else if(a.height()>$(window).height()){
simpleTLWH.height = $(window).height()-50;
simpleTLWH.width = simpleTLWH.height * img_rateWH;
}else{
simpleTLWH.width = a.outerWidth();
simpleTLWH.height = a.outerHeight();
}
simpleTLWH.top = ($(window).height()-simpleTLWH.height)/2 + $(window).scrollTop();
simpleTLWH.left = ($(window).width()-simpleTLWH.width)/2;
jQuery("<div/>")
.attr({
id: "simple_popup"
})
.css({
position:'absolute',
top: simpleTLWH.top,
left: simpleTLWH.left,
width: simpleTLWH.width,
height: simpleTLWH.height,
zIndex: 9950,
cursor: "pointer",
border: "3px solid #333"
})
.appendTo("#index_layer");
$("#simple_img_loading")
.css({
display:'',
width: "100%",
height: "100%"
})
.appendTo("#simple_popup");
jQuery("<div/>")
.attr({
id: "control_box"
})
.css({
opacity : 0,
position:'absolute',
top: 0,
left: 0,
width: "100%",
height: 0,
zIndex: 990,
color: "#FFF",
backgroundColor: "#000"
}).appendTo("#simple_popup");
//drag 이부분은 drag
if(options.drag){
$.getScript("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js", function(){
$("#simple_popup")
.draggable().css('cursor', 'move');
});
}
//drag 끝
//휠 관련 부분
if(options.wheel){
//wheel lib
;(function($){
$.fn.wheel = function( fn ){ return this[ fn ? "bind" : "trigger" ]( "wheel", fn ); };
// special event config
$.event.special.wheel = {
setup: function(){
$.event.add( this, wheelEvents, wheelHandler, {} );
},
teardown: function(){
$.event.remove( this, wheelEvents, wheelHandler );
}
};
// events to bind ( browser sniffed... )
var wheelEvents = !$.browser.mozilla ? "mousewheel" : "DOMMouseScroll"+( $.browser.version<"1.9" ? " mousemove" : "" );
// shared event handler
function wheelHandler( event ){
switch ( event.type ){
case "mousemove": // FF2 has incorrect event positions
return $.extend( event.data, { // store the correct properties
clientX: event.clientX, clientY: event.clientY,
pageX: event.pageX, pageY: event.pageY
});
case "DOMMouseScroll": // firefox
$.extend( event, event.data ); // fix event properties in FF2
event.delta = -event.detail/3; // normalize delta
break;
case "mousewheel": // IE, opera, safari
event.delta = event.wheelDelta/120; // normalize delta
if ( $.browser.opera ) event.delta *= -1; // normalize delta
break;
}
event.type = "wheel"; // hijack the event
return $.event.handle.call( this, event, event.delta );
};
})(jQuery);
// wheel lib end
$("#simple_popup").bind('wheel',function(event,delta){
var chang_size = 50;
// alert($(this).width()+'/'+$(this).height());
if(delta>0){
$(this).css({
top: $(this).offset().top-(chang_size/2),
left: $(this).offset().left-(chang_size/2),
width:$(this).width()+chang_size,
height:($(this).width()+chang_size)*img_rateHW
});
// alert(parseInt(($(this).width()+chang_size)/real_size));
control_box_edit( $(this), "이미지가 확대되었습니다.");
return false;
}else{
$(this).css({
top: $(this).offset().top+(chang_size/2),
left: $(this).offset().left+(chang_size/2),
width:$(this).width()-chang_size,
height:($(this).width()-chang_size)*img_rateHW
});
control_box_edit( $(this), "이미지가 축소되었습니다.");
return false;
}
})
}
}
function iframe_layer(a, option){
jQuery("<div/>")
.attr('id', 'simple_iframe')
.css({
position:'absolute',
width: option.width,
height: option.height,
// top: $(window).height()-option.height,
top: 0,
left: 0,
border: "3px solid #333",
zIndex: 990
// backgroundColor: "000"
})
.appendTo("#blank");
jQuery("<iframe/>")
.attr('src', option.href)
.css({
width: "100%",
height: "100%",
border: "3px solid #333",
zIndex: 990
})
.appendTo("#simple_iframe");
}
publicMethod = $.fn[simplebox] = $.fn.simplebox = $[simplebox] = function (options, callback) {
var $this = this;
options = jQuery.extend(defaults, options);
if (callback) {
options.onComplete = callback;
}
if (!$this[0] || $this.selector === undefined) {
$this = $('<a/>');
options.open = true; // assume an immediate open
}
$this.live("click", function(e){
//블라인드의 종류를 찾아 건다.
if(options.img){
blind($(this), options);
var img_src = options.href || $(this).attr("href") || $(this).attr("src");
jQuery("<img id='simple_img_loading' src='"+img_src+"' style='display:none;' />").appendTo("#index_layer");
$("#simple_img_loading").load(function(){
change_layer($(this), options);
})
}
if(options.iframe && options.href){
iframe_layer($(this), options);
}
return false;
}).css('cursor', 'pointer');
return $this;
};
publicMethod.settings = defaults;
// Initializes simplebox when the DOM has loaded
$(publicMethod.init);
}(jQuery, this));
[이 게시물은 관리자님에 의해 2011-10-31 16:55:28 jQuery에서 이동 됨]
댓글 2개
Sizkein
15년 전
쓸대없는 더미가 생기지 않게 하도록 하기 위해서 blank 내부에 레이어를 집어넣습니다.
고로 $("#blank).remove(); 하시면 모든 창이 지워지겠죠
고로 $("#blank).remove(); 하시면 모든 창이 지워지겠죠
Sizkein
15년 전
사용예제는
http://mqoo.com/bbs/images/17
입니다
http://mqoo.com/bbs/images/17
입니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 530 |
|
19년 전 | 1248 | |
| 529 |
|
19년 전 | 1435 | |
| 528 |
|
19년 전 | 1986 | |
| 527 |
사랑과우정
|
19년 전 | 2399 | |
| 526 | 19년 전 | 2881 | ||
| 525 |
|
19년 전 | 2314 | |
| 524 |
|
19년 전 | 1820 | |
| 523 | 19년 전 | 7065 | ||
| 522 |
|
19년 전 | 3746 | |
| 521 | 19년 전 | 2361 | ||
| 520 | 19년 전 | 2411 | ||
| 519 | 19년 전 | 2915 | ||
| 518 |
|
19년 전 | 5805 | |
| 517 |
|
19년 전 | 5576 | |
| 516 |
|
19년 전 | 2283 | |
| 515 |
|
19년 전 | 3327 | |
| 514 | 19년 전 | 2883 | ||
| 513 | 19년 전 | 2234 | ||
| 512 |
개발자관리자
|
19년 전 | 2743 | |
| 511 |
개발자관리자
|
19년 전 | 1599 | |
| 510 |
개발자관리자
|
19년 전 | 1764 | |
| 509 |
개발자관리자
|
19년 전 | 1877 | |
| 508 |
개발자관리자
|
19년 전 | 2022 | |
| 507 |
개발자관리자
|
19년 전 | 1702 | |
| 506 |
개발자관리자
|
19년 전 | 1828 | |
| 505 |
개발자관리자
|
19년 전 | 1793 | |
| 504 |
개발자관리자
|
19년 전 | 1869 | |
| 503 |
개발자관리자
|
19년 전 | 1532 | |
| 502 |
개발자관리자
|
19년 전 | 2672 | |
| 501 | 19년 전 | 2022 | ||
| 500 | 19년 전 | 3250 | ||
| 499 | 19년 전 | 3279 | ||
| 498 | 19년 전 | 2540 | ||
| 497 | 19년 전 | 2613 | ||
| 496 | 19년 전 | 2467 | ||
| 495 | 19년 전 | 2712 | ||
| 494 | 19년 전 | 2690 | ||
| 493 | 19년 전 | 3205 | ||
| 492 | 19년 전 | 2918 | ||
| 491 | 19년 전 | 5341 | ||
| 490 |
|
19년 전 | 2140 | |
| 489 |
|
19년 전 | 2224 | |
| 488 |
|
19년 전 | 2031 | |
| 487 |
|
19년 전 | 1959 | |
| 486 |
|
19년 전 | 1961 | |
| 485 |
|
19년 전 | 2167 | |
| 484 |
|
19년 전 | 3231 | |
| 483 |
|
19년 전 | 3118 | |
| 482 |
|
19년 전 | 2873 | |
| 481 |
|
19년 전 | 2574 | |
| 480 |
|
19년 전 | 2646 | |
| 479 |
|
19년 전 | 2322 | |
| 478 |
|
19년 전 | 2350 | |
| 477 |
개발자관리자
|
19년 전 | 1612 | |
| 476 |
개발자관리자
|
19년 전 | 2322 | |
| 475 |
개발자관리자
|
19년 전 | 2674 | |
| 474 |
개발자관리자
|
19년 전 | 2676 | |
| 473 |
개발자관리자
|
19년 전 | 2990 | |
| 472 | 19년 전 | 2756 | ||
| 471 | 19년 전 | 1755 | ||
| 470 | 19년 전 | 1850 | ||
| 469 |
|
19년 전 | 2755 | |
| 468 |
|
19년 전 | 2241 | |
| 467 |
|
19년 전 | 4014 | |
| 466 |
|
19년 전 | 2535 | |
| 465 | 19년 전 | 2397 | ||
| 464 | 19년 전 | 3543 | ||
| 463 |
|
19년 전 | 3116 | |
| 462 |
|
19년 전 | 2260 | |
| 461 |
|
19년 전 | 3058 | |
| 460 |
|
19년 전 | 2260 | |
| 459 |
|
19년 전 | 3135 | |
| 458 |
|
19년 전 | 3555 | |
| 457 |
|
19년 전 | 5228 | |
| 456 |
|
19년 전 | 3152 | |
| 455 |
스마일미디어
|
19년 전 | 3144 | |
| 454 |
스마일미디어
|
19년 전 | 2743 | |
| 453 |
스마일미디어
|
19년 전 | 2483 | |
| 452 |
스마일미디어
|
19년 전 | 2741 | |
| 451 |
스마일미디어
|
19년 전 | 2461 | |
| 450 |
스마일미디어
|
19년 전 | 2589 | |
| 449 |
스마일미디어
|
19년 전 | 2379 | |
| 448 |
스마일미디어
|
19년 전 | 2702 | |
| 447 | 19년 전 | 2970 | ||
| 446 |
스마일미디어
|
19년 전 | 3254 | |
| 445 |
스마일미디어
|
19년 전 | 7057 | |
| 444 |
스마일미디어
|
19년 전 | 5176 | |
| 443 |
스마일미디어
|
19년 전 | 2443 | |
| 442 |
스마일미디어
|
19년 전 | 5186 | |
| 441 |
스마일미디어
|
19년 전 | 3120 | |
| 440 |
|
19년 전 | 2488 | |
| 439 | 19년 전 | 2180 | ||
| 438 | 19년 전 | 3578 | ||
| 437 |
|
19년 전 | 2875 | |
| 436 |
|
19년 전 | 3259 | |
| 435 |
|
19년 전 | 2902 | |
| 434 | 19년 전 | 3398 | ||
| 433 |
sjsjin
|
19년 전 | 2732 | |
| 432 |
sjsjin
|
19년 전 | 3467 | |
| 431 |
sjsjin
|
19년 전 | 2433 |
jquery.simplebox.js
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기