Sticky Header after scrolling down

前端 未结 10 1232
野性不改
野性不改 2020-11-27 11:19

I saw this sticky header on this website: http://dunked.com/ (no longer active, view archived site)

When you scroll down the sticky header comes down from t

10条回答
  •  一个人的身影
    2020-11-27 11:55

    I used jQuery .scroll() function to track the event of the toolbar scroll value using scrollTop. I then used a conditional to determine if it was greater than the value on what I wanted to replace. In the below example it was "Results". If the value was true then the results-label added a class 'fixedSimilarLabel' and the new styles were then taken into account.

        $('.toolbar').scroll(function (e) {
    //console.info(e.currentTarget.scrollTop);
        if (e.currentTarget.scrollTop >= 130) {
            $('.results-label').addClass('fixedSimilarLabel');
        }
        else {      
            $('.results-label').removeClass('fixedSimilarLabel');
        }
    });
    

    http://codepen.io/franklynroth/pen/pjEzeK

提交回复
热议问题