2015-10-06 94 views
-2

我有一个网站与溢出滚动的div,所以高度是固定的。 我试图通过点击蓝色按钮来整合滚动,但它运行不正常。它使奇怪的事情。 http://cepidesigns.com.ar/no-cache/cronosREG/jquery滚动效果不好

这是我的javascript代码:

$('a[href*=#]').click(function() { 
    $('.boton').removeClass('clicked'); 
    $(this).find('.boton').addClass('clicked'); 

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+270; 
    console.log($target.offset().top); 
    if(targetOffset==0) 
     return false; 
    $('.main') 
    .animate({scrollTop: targetOffset}, 1000); 
    return false; 
    } 
} 
}); 

你能帮忙吗? 谢谢。

回答

0

我固定它:)

$('a[href*=#]').click(function() { 
    $('.boton').removeClass('clicked'); 
    $(this).find('.boton').addClass('clicked'); 

    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+270; 
     if(targetOffset==0) 
     return false; 

     $('.main') 
     .animate({scrollTop: targetOffset-$('a[name="home"]').offset().top}, 1000); 
    return false; 
    } 
    } 
});