滚动到部分后添加类,当感觉和动画到id时

时间:2015-02-10 13:08:43

标签: javascript jquery alignment

我搜索脚本,这将是滚动期间的行为:http://www.dishoom.com/

我有三个部分的网站,并希望scrollowaniu到该部分的中间均衡它的上部位置。上面的例子是

此致

1 个答案:

答案 0 :(得分:0)

 <script>
        jQuery(document).ready(function ($) {
            $(window).scroll(function () {
                   scroll = $(window).scrollTop();


                var height_check = jQuery(window).height() ;
                $(document).mousewheel(function (event) {
                    if (event.deltaY) {
                        $(window).scroll(function () {

                            if(scroll >= $("section#home_bg").offset().top)
                            {
                                $('section#barman').removeClass('snaps-active');
                                $('section#galeria').removeClass('snaps-active');
                                $('section#home_bg').addClass('snaps-active');

                                if(scroll >= ($("section#home_bg").offset().top + (0.5*height_check)))
                                {
                                    $('section#home_bg').removeClass('snaps-active');

                                }
                            }
                            if (scroll >= $("section#barman").offset().top) {
                                $('section#barman').addClass('snaps-active');
                                $('section#galeria').removeClass('snaps-active');
                                $('section#home_bg').removeClass('snaps-active');

                                if(scroll >= ($("section#barman").offset().top + (0.5*height_check)))
                                {
                                    $('section#barman').removeClass('snaps-active');

                                }

                            }
                            if(scroll >= ($("section#galeria").offset().top)) {
                                $('section#home_bg').removeClass('snaps-active');
                                $('section#barman').removeClass('snaps-active');
                                $('section#galeria').addClass('snaps-active');


                                if (scroll >= ($("section#galeria").offset().top + (0.5 * height_check))) {
                                    $('section#galeria').removeClass('snaps-active');
                                }


                            }


                        });






                    }









                });





            });



        });
    </script>