简体   繁体   English

导航栏不起作用

[英]Navigation bar not working

I am doing a scrolling horizontal website similar to http://www.apple.com/mac-pro/ (they seemed to have changed it) but mine is horizontal. 我正在做一个类似于http://www.apple.com/mac-pro/的水平滚动网站(它们似乎已经更改了它),但是我的水平网站。 However, I am experiencing a problem where the 6 white navigation bars do not light up and correspond to the page that is being navigated to. 但是,我遇到了一个问题,即6个白色导航栏没有点亮并且与要导航到的页面相对应。 My code is as follows below. 我的代码如下。 Thanks in advance! 提前致谢! Here is an example http://jackyeu.com/sp3beta/ I am trying to do the navigation circles on the right side. 这是一个示例http://jackyeu.com/sp3beta/我正在尝试在右侧进行导航。

$(function(){
    var _left = $(window).scrollLeft();
    var individualDivWidth = 1024;

    $(window).scroll(function(){
        var _cur_left = $(window).scrollLeft();
        var totalWidth = $('#container').width();
        var posToScroll = Math.round(_cur_left / individualDivWidth) * individualDivWidth;

        TweenMax.to($('html, body'), 0.5, {scrollLeft: posToScroll, overwrite:true});


if ($(window).scrollLeft() >= $('#index_container').width() )
{
        $(".b1").css({ background: "#569EB2"});
        $(".b2").css({ background: "#FFF"});
        $(".b3").css({ background: "#FFF"});
        $(".b4").css({ background: "#FFF"});
        $(".b5").css({ background: "#FFF"});
        $(".b6").css({ background: "#FFF"});
}

if ($(window).scrollLeft() >    = $('#page1_container').width() )
{
        $(".b1").css({ background: "#FFF"});
        $(".b2").css({ background: "#569EB2"});
        $(".b3").css({ background: "#FFF"});
        $(".b4").css({ background: "#FFF"});
        $(".b5").css({ background: "#FFF"});
        $(".b6").css({ background: "#FFF"});
}


    });<!-- end of scroll funcion -->'

Looking at the source of the second link you provided ( here ) you can see a reference to <script src="js/parallax.js"></script> 查看您提供的第二个链接的来源( 此处 ),您可以看到对<script src="js/parallax.js"></script>的引用。

With this code: 使用此代码:

/* Set navigation dots to an active state as the user scrolls */
function redrawDotNav(){
  var section1Top =  0;
  // The top of each section is offset by half the distance to the previous section.
  var section2Top =  $('#shoe-kits').offset().top - (($('#details').offset().top - $('#shoe-kits').offset().top) / 2);
  var section3Top =  $('#details').offset().top - (($('#about').offset().top - $('#details').offset().top) / 2);
  var section4Top =  $('#about').offset().top - (($(document).height() - $('#about').offset().top) / 2);;
  $('nav#primary a').removeClass('active');
  if($(document).scrollTop() >= section1Top && $(document).scrollTop() < section2Top){
    $('nav#primary a.campaign-banner').addClass('active');
  } else if ($(document).scrollTop() >= section2Top && $(document).scrollTop() < section3Top){
    $('nav#primary a.shoe-kits').addClass('active');
  } else if ($(document).scrollTop() >= section3Top && $(document).scrollTop() < section4Top){
    $('nav#primary a.details').addClass('active');
  } else if ($(document).scrollTop() >= section4Top){
    $('nav#primary a.about').addClass('active');
  }
}

this is bound to the window scroll event at the top of this file like so: 绑定到此文件顶部的窗口滚动事件,如下所示:

/* Scroll event handler */
$(window).bind('scroll',function(e){
  redrawDotNav();
});

What this code is doing is fetching the offsets of each section (and not storing these in some var with a higher scope (shame on them :P) then comparing the current scroll height to each of these to figure out which section you have scrolled to. 这段代码要做的是获取每个部分的偏移量(而不是将它们存储在范围更大的var中(它们对:P感到羞耻),然后将当前滚动高度与每个偏移量进行比较,以确定您滚动到了哪个部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM