简体   繁体   中英

Horizontal scrolling page links don't work from another page

I have a section within my page that scrolls horizontally with the help of some Javascript. The issue is the links to these horizonal sections don't work if I reference them from another page. The working example is here ("What We Offer" sub links in the main navigation): http://fitnessacademysurrey.cloudlevel.me

If I navigate to the blog page and then use the "What We Offer" sub-links, they don't do anything.

Here's the code for the links:

$(document).ready(function () {
var sildeNum = $('.page').length,
    wrapperWidth = 100 * sildeNum,
    slideWidth = 100/sildeNum;
$('.wrapper').width(wrapperWidth + '%'); 
$('.page').width(slideWidth + '%');

$('a.scrollitem').click(function(){
    $('a.scrollitem').removeClass('selected');
    $(this).addClass('selected');

    $('#nav-subnav ul li').removeClass('active');
    $('.panelHeading').addClass('hidden');
    $("a.scrollitem").each(function(index) {
    if($(this).hasClass("selected"))
        $("#nav-subnav ul li:nth-child("+(index+1)+")").addClass("active"),
        $(".panelHeading:nth-child("+(index+2)+")").removeClass("hidden");
    });

    $('#nextLink').removeClass('disabled');
    $('#previousLink').removeClass('disabled');
    if($('#nav-subnav ul li.active').is(':last-child'))
        $('#nextLink').addClass('disabled');

    if($('#nav-subnav ul li.active').is(':first-child'))
        $('#previousLink').addClass('disabled');

    var slideNumber = $($(this).attr('href')).index('.page'),
        margin = slideNumber * -100 + '%';

    $('.wrapper').animate({marginLeft: margin},500);
    return false;

  });
});
$( function() {
  var hash = window.location.hash;
  if (hash.length > 1) {
    $("[href='" + hash + "']").click();
  }
});

previousLink and nextLink are for additional navigation, but I don't think this is relevant.

Can anyone help?

Well the problem is you use JavaScript to scroll the page so you need to add code that reads the hash and finds the right link and clicks it.

$( function() {
    var hash = window.location.hash;
    if (hash.length > 1) {
        $("[href='" + hash + "']").click();
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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