JQuery 플러그인안에서 Window Load 사용하는 법

JQuery 플러그인안에서 Window Load 사용하는 법

QA

JQuery 플러그인안에서 Window Load 사용하는 법

본문

플러그인 공부중인데 

window load에서만 제대로 작동합니다.

 

플러그인 내에서 window load 작성요령을 알고 싶습니다.

resize도 알려주시면 감사합니다.

 


(function($){
	$.fn.parcon = function(option,callback){
		if($.isFunction(option)){
			callback = option;
			option = null;
		}		
		
		$.fn.parcon.setting = {
			column: 4,
			margin: 10,
			padding: 15,
			background: "transparent"
		};
			
 
		option = $.extend($.fn.parcon.setting,option);
		return this.each(function(){
			var i = 0;
			$(this).find("li").each(function(){
				var obJecty = $(this);
				var winW = $(window).width();
				var thisIdx = $(this).index();
				var thisPrevL = parseInt($(this).prev().css("left"));
				var thisPrevT = parseInt($(this).prev().css("top"));
				var prevW = $(this).prev().outerWidth(true);
				var thisMrg = option.margin;
				var thisPdd = option.padding;
				var lineLen = option.column;
				var backColor = option.background;
				
				$(this).css({
					"padding" : thisPdd,
					"box-sizing": "border-box",
					"background-color": backColor,
					"position": "absolute",
					"top": 0,
					"left": 0
				});
				
				if (thisIdx < lineLen){
					i++;
					if(thisIdx != 0){
						$(this).css({"width": prevW, "left": (thisPrevL + prevW) + thisMrg, "top": thisMrg});
					} else {
						$(this).css({"width": (winW - (thisMrg*(lineLen+1)))/lineLen, "left": thisMrg, "top": thisMrg});
					}
				} else if(thisIdx >= lineLen ){
					var topLi = $(this).parent().find("li").eq(thisIdx - lineLen);
					var topLiH = topLi.outerHeight(true);
					var topOff = topLi.offset();
					var topOffT = topOff.top;
 
					if(i%lineLen != 0){
						i++;						
						$(this).css({"width": prevW, "left": (thisPrevL + prevW) + thisMrg, "top": (topOffT + topLiH) + thisMrg});
					} else {
						i++;
						$(this).css({"width": prevW, "left": thisMrg, "top": (topOffT + topLiH) + thisMrg});	
					}
				}
			});
		});
	}
})(jQuery);

이 질문에 댓글 쓰기 :

답변 1

정확한 질문 내용은 잘 모르겠는데요....

 

window load 는

$(window).load(function(){
   제이쿼리 내용
});

으로 사용하시면 됩니다.

현재 소스는

(function($){
 제이쿼리 내용
});

인데 이것은
$(document).ready(function(){
   제이쿼리 내용
});

와 같은 방식이고 축약형입니다.

jQuery ready와 load의 차이는

http://ojtiger.com/179

여기 참고해 보세요.

 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 141
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT