我使用下列固定導航插件 - https://codyhouse.co/demo/vertical-fixed-navigation/index.html垂直固定導航時部分不是全高
它的偉大工程時,每節都有100%的高度,因爲它挑選部分的中心,但我的部分不是100%的高度。
有沒有一種方法來適應這與小部分工作?
正如你所看到的,它甚至不突出的頂部或底部的部分,因爲它們不是在屏幕的中心點。
JS:
jQuery(document).ready(function($){
var contentSections = $('.cd-section'),
navigationItems = $('#cd-vertical-nav a');
updateNavigation();
$(window).on('scroll', function(){
updateNavigation();
});
//smooth scroll to the section
navigationItems.on('click', function(event){
event.preventDefault();
smoothScroll($(this.hash));
});
//smooth scroll to second section
$('.cd-scroll-down').on('click', function(event){
event.preventDefault();
smoothScroll($(this.hash));
});
//open-close navigation on touch devices
$('.touch .cd-nav-trigger').on('click', function(){
$('.touch #cd-vertical-nav').toggleClass('open');
});
//close navigation on touch devices when selectin an elemnt from the list
$('.touch #cd-vertical-nav a').on('click', function(){
$('.touch #cd-vertical-nav').removeClass('open');
});
function updateNavigation() {
contentSections.each(function(){
$this = $(this);
var activeSection = $('#cd-vertical-nav a[href="#'+$this.attr('id')+'"]').data('number') - 1;
if (($this.offset().top - $(window).height()/2 < $(window).scrollTop()) && ($this.offset().top + $this.height() - $(window).height()/2 > $(window).scrollTop())) {
navigationItems.eq(activeSection).addClass('is-selected');
}else {
navigationItems.eq(activeSection).removeClass('is-selected');
}
});
}
function smoothScroll(target) {
$('body,html').animate(
{'scrollTop':target.offset().top},
600
);
}
});
當你說100%的身高,你的意思是100%的屏幕高度? –
是的,抱歉,我應該更具體。我的部分不是100%的瀏覽器高度,與小提琴相同。有沒有一種方法來適應這種情況,以便在瀏覽器底部觸及div頂部時突出顯示該部分? – Madness
我不明白你是什麼意思突出這一節?像改變顏色突出顯示或者你想完全居中? –