JQuery > ScrollTo > highlighting the item that was

2019-06-05 04:08发布

问题:

This seems pretty simple, but I can't seem to figure it out. I want to change the background color of the element that was scrolled to using the ScrollTo plugin for JQuery. I'm using the onAfter setting. This is what I have:

$("#nav-inpage").localScroll({
  target:'body',
  offset: -50, // compensate for static super-nav
  hash: true,
  onAfter:function(){
    $(this.hash).css('background-Color' , '#ff0000');
  }
});

If I change this.hash to just this, the background of the target (body) turns red. So how do I address the hash that I'm scrolling to?

回答1:

You need to actually fetch the hash and use it as an ID selector.

$(window.location.hash).css('background-Color' , '#ff0000');