Pergunta

Does anyone know how add to this script?

I need to check whether the visitor is at the top of the page? If not call the fallback script.

E.g. if user is at top of page delay animation, if user is elsewhere remove delay (fallback else condition).

var viewportWidth = $(window).width(),
    stopTabletAnimation = 1024,
    scrTop;

$(window).on("load scroll", function() {
    scrTop = $("html, body").scrollTop();
    if (!scrTop && viewportWidth > stopTabletAnimation){
        // DELAY ANIMATION - FORCE TOP CORRECTLY (WITH A DELAY - .9s)
        $('.website-navigation').delay(3500).animate({top:0}, 900, function() {
            // Confirm Above if successful!
            console.log('ANIMATION COMPLETE: .site-head Delayed, then loaded!');
        });

    } else {
        // Do Not Animate
        $('.website-navigation').css({top: '0'});
        console.log('NO ANIMATION: Inforce Set Height');
    }
});
Foi útil?

Solução

Change the check from

scrTop = $("html, body").scrollTop();

To

scrTop = $("body").scrollTop();

This will detect how far away from the top the user is.

Edit: This should be set with

scrTop = $(window).scrollTop();

Ass explained here: https://stackoverflow.com/a/2422159/1809751

Outras dicas

var scrTop;

$(window).on("load scroll", function() {
  scrTop = $("html, body").scrollTop();
  if(!scrTop){ //if scrollTop is at 0

  }else{

  }
});

or in your case probably something like:

if (!scrTop && viewportWidth > stopTabletAnimation){
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top