Change CSS element with JQuery when scroll reaches an anchor point

前端 未结 3 1194
不知归路
不知归路 2020-11-28 08:51

I currently have this solution to change the css elements when the page reaches a certain point but I\'d like to use an #anchor-point instead of the pixel value (1804) to be

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 09:27

    Try this:

    var targetOffset = $("#anchor-point").offset().top;
    
    var $w = $(window).scroll(function(){
        if ( $w.scrollTop() > targetOffset ) {   
            $('#voice2').css({"border-bottom":"2px solid #f4f5f8"});
            $('#voice3').css({"border-bottom":"2px solid #2e375b"});
        } else {
          // ...
        }
    });
    

提交回复
热议问题