ie 7 window resize

1464 단어 window
오늘 회사 가 이 사 를 가 려 고 하 는데 정말 시끄럽게 하루 를 보 내 서 자 바스 크 립 트 를 조금 배 웠 습 니 다.
 
ie 6, ie 7 은 window resize 에 여러 번 나타 납 니 다.
 
$(function(){

     $(window).resize(function(){

        //    
        alert(1);

       //IE 6 , IE7           
       height = $(window).height();

       eventId = setTimeout(function(){

           newHeight = $(window).height();
           if(newHeight == height){
              alert(1);
              clearTimeout(eventId);
           }
        },1000)

     });

})

//                
//date 2014 12 20 
	tempHeight = 0 ; 
		tempWidth = 0 ; 
		timeoutId = 0 ; 
		var clearId = function(max){
		
			for(var i = 0 ; i <= max ; i++){
				clearTimeout(i);
			}
		}
		
		$(window).resize(function(){
			timeoutId = setTimeout(function(){
			 
				alert(1);
				alert("time out id is "+timeoutId);
				clearId(timeoutId);
			 
			},500);
			 
		})


 위의 방법 은 내 가 스스로 해결 하 는 것 이다. 아래 는 인터넷 에 더욱 넓 은 방법 을 제공 하고 효율 이 좀 더 높 을 것 이다.
 
$(window).resize($.debounce(1000, function(){
		
			alert(1);
		
		}));

http://stackoverflow.com/questions/1500312/dom-onresize-event 이 연결 참조 

좋은 웹페이지 즐겨찾기