2013-10-18 25 views
0

我有一個Flexslider可容納項目的所有內容。在這種情況下,每個「頁面」或幻燈片具有不同的內容,如更新,項目,關於和聯繫。Flexslider body scroll僅適用於當前幻燈片(V2)

這些頁面有不同的長度,有些需要滾動條,有些則不需要。在不需要滾動的頁面上,內容下方有大量空白空間。這個空間被內容佔據在其他頁面上。

我使用jQuery來查找li.flex-active-slide和窗口的高度,並且這工作正常。如果在點擊導航欄時li.flex-active-slide類發生變化,我無法弄清楚如何告訴jQuery。

這裏是我的Flexslider代碼:

$(document).ready(function() { 
    //set some variables for calculating the hash 
    var index = 0, hash = window.location.hash; 
    //via malsup (Cycle plugin), calculates the hash value 
    if (hash) { 
     index = /\d+/.exec(hash)[0]; 
     index = (parseInt(index) || 1) - 1; 
    } 
    $(window).trigger('resize'); 
    $('#mainflexslider').flexslider({ 
     animation: "fade", 
     slideDirection: "horizontal", 
     keyboardNav: false, 
     slideshow: false, 
     animationSpeed: 500, 
     controlsContainer: ".flex-container", 
     manualControls: ".flex-control-nav li", 
     startAt: index, 
     after:function(slider){ 
      window.location.hash = slider.currentSlide+1; 
     } 
    }); 
}); 

(旁註:。而點擊進入導航信貸的問題及相應的答案是here網址正在更新)

而對於尋找身高:

$(window).load(function() { 
    var slideHeight = $("li.flex-active-slide").height(); 
    var windowHeight = $(window).height(); 

    if (slideHeight > windowHeight) { 
     $('html, body').css('overflowY', 'auto'); 
    } 
    else { 
     $('html, body').css('overflowY', 'hidden'); 
    } 
}); 

我想知道是否有辦法將這兩個代碼結合起來?

如果不是,Flexslider在追加li.flex-active-slide類時如何判斷jQuery?

+0

你可以把代碼找回後面的高度回調 –

回答

1

你可以試試這個

$(window).load(function() { 
var index = 0, hash = window.location.hash; 
//via malsup (Cycle plugin), calculates the hash value 
if (hash) { 
    index = /\d+/.exec(hash)[0]; 
    index = (parseInt(index) || 1) - 1; 
} 
$(window).trigger('resize'); 
$('.flexslider').flexslider({ 
    animation: "fade", 
    slideDirection: "horizontal", 
    keyboardNav: false, 
    slideshow: false, 
    animationSpeed: 500, 
    controlsContainer: ".flex-container", 
    manualControls: ".flex-control-nav li", 
    startAt: index, 
    after:function(slider){ 
     window.location.hash = slider.currentSlide+1; 
     sliderheight(); 
    }, 
    start:function(slider){ 
     sliderheight(); 
    } 
}); 
function sliderheight(){ 
    var slideHeight = $("li.flex-active-slide").height(); 
     var windowHeight = $(window).height(); 
     console.log(slideHeight+" > "+windowHeight); 
     if (slideHeight > windowHeight) { 
      $('html, body').css('overflow-y', 'auto'); 
     } 
     else { 
      $('html, body').css('overflow-y', 'hidden'); 
     } 
} 
});  

創建一個函數與溢出-Y的所有代碼,並從回調調用它,它可對前,後或開始

+0

完美!一些細微的修改是必要的,但它很好用!非常感謝你的幫助! :) – nnavaille