2016-07-28 33 views
0

我想動畫一個單一的分頁網站,當我點擊菜單,它滾動到該節,我添加了一個簡單的動畫與恆定的速度,但我想這樣的事情,當你點擊在菜單上>>>http://www.sergioarantes.com/
我發現jQuery的寬鬆政策能夠幫助這裏是我的js代碼「它不工作」滾動與緩動jQuery

$(document).ready(function(){ 

$("#first-showup header nav .nav-bar #menu-items ul li a").click(function(){ 

var $block = $(this).data("block"); 

var $thisBlock = $("#"+$block); 


    $("html, body").animate({ 
    "scrollTop": $thisBlock.position().top }, 
      { 
       duration: 1200, 
       easing: "easeInOutExpo" 
      }); 
    }); 

它們對這部動畫的網站,他們說,使用這種模式:

div.animate({ top: '-=100px' }, 600, 'easeInQuart', function() { … }) 

但我無法修改我的代碼 謝謝

Richard。

+0

你有'jsfiddle'或東西表現出更多的是怎麼回事你的代碼? – tcasey

+0

這裏是:https://jsfiddle.net/6ta43p1z/ –

回答

0

jQuery方法$(selector).animate();需要包含一些CSS屬性camelCase編寫的第一個參數a Object。酒店scrollTop不是CSS屬性。在任何情況下,你能解決這個問題,在某些方面,如:

  • 創建一個Javascript/jQuery的功能設置文檔scrollTop屬性,你可以用一個簡單的window.setInterval();
  • 用途基本上做一個CSS招數(請看Scroll Based Animations jQuery CSS3)在頁面上滾動效果並對其進行動畫處理。

祝你好運!

2

這應該爲你工作

$(document).ready(function(){ 

     $("#first-showup header nav .nav-bar #menu-items ul li a").click(function(){ 

     var $block = $(this).data("block"); 

     var $thisBlock = $("#"+$block); 

      $('html, body').animate({ 
       scrollTop: $thisBlock.offset().top 
      }, 1000); 

     }); 
    }); 
+0

[這裏](https://repl.it/ChIL)是工作演示 – tcasey