간이 페이지 장면 스크롤 jquery 플러그인

4031 단어 jquery 플러그인
(function($){
    $.extend($.fn, {
        scene_scroll:function(arg_obj){
            //  
            //  
            var $scene_arr = arg_obj.$scene_arr || (function(){console.log(" , $scene_arr");})(),
            //  
            $nav =  arg_obj.$nav || (function(){console.log(" , $nav");})(),
            //  
            event_name = arg_obj.event_name || "click",
            //  
            speed = arg_obj.speed || 400,
            //  
            scroll_callback = arg_obj.scroll_callback || (function(){return function(){}})(),
            //  
            stop_next_event = arg_obj.stop_next_event || false,

            nav_height_arr = [0],
            chrome_browser_flag = navigator.userAgent.indexOf("AppleWebKit");

            $scene_arr.each(function(){
                var div_height = $(this).height();
                nav_height_arr.push(div_height)
            });
            $nav.on(event_name,function(){
                var pos = $.inArray(this, $(".nav").find("a"));
                var sum_pos = 0;
                
                for(var i=0; i<=pos; i++){
                    sum_pos = sum_pos + nav_height_arr[i];
                }
                
                // chrome 
                (chrome_browser_flag > -1 ) ? $("body").animate({scrollTop:sum_pos}, speed, scroll_callback):
                // IE,Firefox 
                $(document.documentElement).animate({scrollTop:sum_pos}, speed, scroll_callback);
                if(!stop_next_event) return false;

            });
        }
    })
})(jQuery);

좋은 웹페이지 즐겨찾기