var _w;
var _sections;
function init()
{
create();
addEvent();
}
var _isInSections = [];
function create()
{
_w = $( window );
_sections = $( "#sections" ).children( "section" );
_sections.each( function( $index ){
_isInSections = false;
})
}
function addEvent()
{
scrollEvent( null );
_w.on( "scroll", scrollEvent );
resizeEvent( null );
_w.on( "resize", resizeEvent );
}
function scrollEvent( $e, $w, $h )
{
var sT = _w.scrollTop();
var sectionThis;
_sections.each( function( $index ){
sectionThis = $( this );
if( sT > ( sectionThis.offset().top - _w.height()) + _w.height() / 2 )
{
if( _isInSections[ $index ] == true ) return;
switch( $index )
{
case 0 : console.log( "여기1" );
break;
case 1 : console.log( "여기2" );
break;
case 2 : console.log( "여기3" );
break;
case 3 : console.log( "여기4" );
break;
case 4 : console.log( "여기5" );
break;
default : console.log( "여기6" );
break;
}
_isInSections[ $index ] = true;
}
})
}
function resizeEvent( $e )
{
var w = _w.width();
var h = _w.height();
scrollEvent( w, h );
}
'javascript > sample' 카테고리의 다른 글
비오는 효과 제이쿼리 (0) | 2018.11.08 |
---|---|
제이쿼리 이미지 슬라이드 (0) | 2018.11.07 |
swiper 탭 슬라이드 (2) | 2018.06.28 |
jquery 슬라이더 (0) | 2018.06.28 |
jquery 별점 체크 (0) | 2018.06.27 |