Performance suggestion on sticky headers

AlexT

Registered
The jQuery scroll() event handler is used whenever the window scroll position is changed. As such, it is fired quite frequently, which can add noticable CPU processing to low-CPU devices. While I don't know if there is a better way to handle sticky headers (for example by only firing an event when the aboveHeight variable is exceeded, or by setting a timer as suggested in the link), at least, you could considerably improve performance by optimizing some code in the the xb_js_head template. Try to minimize the number of scroll() event handlers to one. For example,

Code:
$(window).scroll(function(){
    if ($(window).scrollTop() > aboveHeight){
    $('.navFloatwrapper').addClass('fixed');
    <xen:if is="[email protected]_logoinnav">
    $('#logoBlock').css('margin-top', navwrapper);
    </xen:if>
    } else {
    $('.navFloatwrapper').removeClass('fixed');
    <xen:if is="[email protected]_logoinnav">
    $('#logoBlock').css('margin-top','0px');
    </xen:if>
    }
});

<xen:if is="[email protected]_floatsubnav">
$(window).scroll(function(){
    if ($(window).scrollTop() > aboveHeight){
    $('.tabLinks').addClass('displaynone');
    } else {

    $('.tabLinks').removeClass('displaynone');
    }
});
</xen:if>
Could be combined into something similar to this:
Code:
$(window).scroll(function(){
    if ($(window).scrollTop() > aboveHeight){
    $('.navFloatwrapper').addClass('fixed');
    <xen:if is="[email protected]_logoinnav">
    $('#logoBlock').css('margin-top', navwrapper);
    </xen:if>
    <xen:if is="[email protected]_floatsubnav">
    $('.tabLinks').addClass('displaynone');
    </xen:if>
    } else {
    $('.navFloatwrapper').removeClass('fixed');
    <xen:if is="[email protected]_logoinnav">
    $('#logoBlock').css('margin-top','0px');
    </xen:if>
    <xen:if is="[email protected]_floatsubnav">
    $('.tabLinks').removeClass('displaynone');
    </xen:if>
    }
});
 
Last edited:

Russ

Pixel Exit Staff
Thanks Alex, we'll combine them for the next release and we'll test out the delay scroll as well, seems simple enough.

That floating navigation gave me a headache with all the options we had to put in because of the various setups xenbase can give you hah. :D
 

Russ

Pixel Exit Staff
The initial suggestion is implemented, we're still looking into the event handlers however at a later release. Thanks for the suggestion @AlexT
 

Pre-Sale Questions

If you have any questions or concerns you want to ask before you make a purchase don't hesitate to use one of our multiple support channels for your convenience.