→

JavaScript программирование →  Scroll плагин для Jquery

Тем, кому нужен яваскриптовый скрол, есть хороший плагин для Jquery
1

JavaScript программирование →  Мягкий (smooth) cкролл (прокрутка, scroll) окна (блока) при помощи JQuery


function enable_smooth_scroll() {
    function filterPath(string) {
        return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
   
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
   
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if ($(this.hash).length) {
                    $(this).click(function(event) {
                        var targetOffset = $(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        $(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}
 


Что делать с функцией


В html прописываем:

<script>
$(document).ready(function() {
    enable_smooth_scroll();
});
</script>
<a href="#fuck">ХУЙ</a>
<div id="fuck"></div> <!-- Размещаем блок в качестве якоря туда, куда нужно крутить. Это не обязательно должен быть div -->
 


UPD: http://demo.php5.com.ua/smooth-scroll/ добавил демо

--
На правах рекламы: Уроки по фотошоп
--
1
10