0

I'm using jmpress.js for my site where you can get to specific content / slides with anchors like follows: index.htm#/slide1, index.htm#/slide2, etc

I'm also using code like

$('.click').click(function () {
    $(".menu").animate({ top: '+=100' });
    $("#logo").fadeToggle();
});

to show and hide different stuff when getting to another slide (if the user clicks on ".click" another slide is coming in from the bottom, replacing the home page). This obviously only works as far as you always start on the "start" page (without any anchors).

But when you visit the page directly with the url index.htm#/slide1 the two items obviously won't show or hide anymore - they should automatically as soon as the user is on any site except the start page though. Is there an easy way (I have no idea of coding) to do this?

So basically something like this:

IF anchor #slide1, #slide2 {
    $(".menu").animate({ top: '+=100' });
    $("#logo").fadeToggle();
});
4

1 回答 1

2
if (window.location.hash){
      var hash = window.location.hash.substring(1);
      if (hash == "slide1" || hash == "slide2"){
         $(".menu").animate({ top: '+=100' });
         $("#logo").fadeToggle();
      }
}

http://curtisimson.co.uk/js/reading-url-hashtag-values/

于 2013-04-23T12:54:52.630 回答