2014-09-24 26 views
2

我期待創建一個簡單的視差分割屏幕網站,允許我在加載新屏幕後交替滾動。例如,如果向下滾動並顯示左側和右側的內容,我想鎖定右側,只有在左側滾動時纔會滾動,直到內容完成。交替滾動邊的視差分割屏幕

所以應該這樣開始:

http://alvarotrigo.com/blog/multiscroll-js-jquery-plugin-to-create-multi-scrolling-sites-with-two-vertical-layouts/

但是一旦我的部分負荷只需要向左滾動這樣的:

http://www.themealings.com.au/leesa/portfolio/nick-jr-parents-blog/

一旦左側含量完成我想提出一個新的部分。關於這可能發生的任何想法?什麼是最好的JS庫來實現這一目標?

回答

0

有幾個插件可以很容易地做到這一點。

給這個一杆----->http://viget.com/inspire/jquery-stick-em

演示在這裏:----->http://davist11.github.io/jQuery-Stickem/

我目前使用這種硬代碼來完成類似的事情,所以這可能是使用還有:

var $window = $(window), 
    $mainMenuBar = $('#fixed-div'), //This div will scroll until top 
    $menuBarOffset = $mainMenuBar.offset().top, 
    window_top = 0, 
    footer_offset = $("#end-div").offset().top, //this div tells #fixed-div when to start scrolling 
    content = $("#unaffected-div"), //This div scrolls like normal 
    panel_height = $mainMenuBar.outerHeight()+'px'; 


$window.scroll(function() { 
    window_top = $window.scrollTop(); 

    if (window_top >= $menuBarOffset) { 
     if (window_top >= footer_offset) { 
      $mainMenuBar.removeClass('stick'); 
      content.css('margin-top', 0); 
     } else { 
      $mainMenuBar.addClass('stick'); 
      content.css('margin-top', panel_height); 
     } 
    } 
    else { 
     $mainMenuBar.removeClass('stick'); 
     content.css('margin-top', 0); 
    } 
}); 

您還需要將此元素添加到您的.css文件

.stick { 
position: fixed; 
top: 0; 
} 
+0

感謝您的意見。我嘗試過使用stick-em,但沒有運氣。我使用基金會作爲框架工作,它禁用容器上的定位。該腳本被加載,但它不是,但它不激活類更改。我會更多地和它一起玩。如果我無法弄清楚,我會舉個例子。再次感謝您的回覆。 – Cpawl 2014-09-25 19:54:53

+0

這裏是一個例子 - 這麼簡單但不知道問題可能是什麼http://cpawl.com/test/scroll/ – Cpawl 2014-09-25 20:24:01

+0

stickem不工作的原因是因爲它沒有正確加載插件腳本。它看起來像你還沒有加載任何jQuery庫 包括此爲在你的文檔中的第一個腳本鏈接,看看你是否有更好的結果 – 2014-09-25 21:04:33