jQuery實現(xiàn)錨點scoll效果實例分析

字號:


    這篇文章主要介紹了jQuery實現(xiàn)錨點scoll效果,實例分析了錨點scoll效果的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    本文實例講述了jQuery實現(xiàn)錨點scoll效果的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
    代碼如下:
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
    var $target = $(this.hash);
    $target = $target.length && $target
    || $('[name=' + this.hash.slice(1) +']');
    if ($target.length) {
    var targetOffset = $target.offset().top;
    var obj = document.documentElement;
    if (jQuery.browser.safari)
    obj = document.body
    if (jQuery.browser.msie)
    obj = 'html';
    $(obj).animate({scrollTop: targetOffset}, 1000);
    return false;
    }
    }
    });
    希望本文所述對大家的jQuery程序設計有所幫助。