JQuery > ScrollTo > highlighting the item that was scrolled to

て烟熏妆下的殇ゞ 提交于 2019-12-08 04:16:23

问题


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');


来源:https://stackoverflow.com/questions/7730400/jquery-scrollto-highlighting-the-item-that-was-scrolled-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!