JQuery > ScrollTo > highlighting the item that was

2019-06-05 04:16发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-06-05 04:46

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

$(window.location.hash).css('background-Color' , '#ff0000');
查看更多
登录 后发表回答