gpt4 book ai didi

滚动期间的 jQuery 粘性导航中心

转载 作者:行者123 更新时间:2023-11-28 13:21:20 25 4
gpt4 key购买 nike

如何在滚动期间设置导航的宽度。导航在滚动期间适合 100% 宽度。如果我将宽度设置为 500px,而不是它的 left:0 定位。在左侧,我无法将导航设置为自动居中。

http://jsfiddle.net/aY8a7/

$(function() {

var sticky_navigation_offset_top = $('#sticky_navigation').offset().top;

var sticky_navigation = function(){
var scroll_top = $(window).scrollTop(); // our current vertical position from the top

if (scroll_top > sticky_navigation_offset_top) {
$('#sticky_navigation').css({ 'position': 'fixed', 'top':0, 'left':0 });
} else {
$('#navigation_menu').css({ 'position': 'relative' });
}
};

sticky_navigation();

$(window).scroll(function() {
sticky_navigation();
});

});

最佳答案

试试这个:http://jsfiddle.net/aY8a7/1/

$(function() {

var sticky_navigation_offset_top = $('#sticky_navigation').offset().top;

var sticky_navigation = function(){
var scroll_top = $(window).scrollTop(); // our current vertical position from the top
var $ul = $('#sticky_navigation ul').width()+'px';

if (scroll_top > sticky_navigation_offset_top) {
$('#sticky_navigation').css({ 'position': 'fixed', 'top':0, 'left':0 });
$('#sticky_navigation ul').css({'width':$ul, 'display':'block', 'text-align':'center'});
} else {
$('#navigation_menu').css({ 'position': 'relative' });
}
};

sticky_navigation();

$(window).scroll(function() {
sticky_navigation();
});

});

关于滚动期间的 jQuery 粘性导航中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14602629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com