tab Fixed

tab Fixed img bg class

by Park Mino

JavaScript

$(window).load(function(){
	var rtime, 
		timeout = false, 
		delta = 200;	
	$(window).resize(function() {
	    rtime = new Date();
	    if (timeout === false) {
	        timeout = true;
	        setTimeout(resizeend, delta);
	    }
	});
	function resizeend() {
	    if (new Date() - rtime < delta) {
	        setTimeout(resizeend, delta);
	    } else {
	        timeout = false;
	        scrollTab();
	    }               
	}
	
	scrollTab();	
	function scrollTab(){
		var 	_tab = $('.treeTab'),
				_tabh = _tab.height(),
				_tabTop = _tab.offset().top,
				_eventTabFixed2 = $('#eventTabFixed2'),
				_tabBox = $('.tabBox');
				
		_eventTabFixed2.css('height', _tabh+'px');		
		_tabBoxArry = [];
		_tabBox.each(function(){
			_tabBoxArry.push($(this).offset().top - _tabh);
		});
		
		$(window).scroll(function(){
			var scrollTop  = $(document).scrollTop();			
			if(scrollTop<_tabBoxArry[1]){
				_eventTabFixed2.attr('class', 'tab01')
			}else if(scrollTop >= (_tabBoxArry[1]) && scrollTop < (_tabBoxArry[2])){
				_eventTabFixed2.attr('class', 'tab02')
			}else if(scrollTop >= (_tabBoxArry[2])){
				_eventTabFixed2.attr('class', 'tab03')
			}
			
			if(scrollTop>=_tabTop){
				_eventTabFixed2.css({'position':'fixed','top':'0'});
			}else{
				_eventTabFixed2.css({'position':''});
			}
		});		
	}
});