Jquery sticky menu not being caught by footer

后端 未结 2 544
借酒劲吻你
借酒劲吻你 2021-01-21 11:13

Can anyone help me pinpoint the issue with my script please?

$(function () {
var top = $(\'#sidebar\').offset().top - parseFloat($(\'#sidebar\').css(\'marginTop\         


        
2条回答
  •  后悔当初
    2021-01-21 11:26

    The problem is that you are forgetting the margin-top of your sidebar in your calculation:

    var maxY = footTop - $('#sidebar').outerHeight() - 68;
    

    In your Prototype JSFiddle the sidebar just happened to have no margin-top.


    On a sidenote: you may want to cache your selectors to improve performance. If you use the same selector more than once, for example $("#sidebar"), put it in a variable:
    var sidebar = $("#sidebar");.

提交回复
热议问题