문제

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');
    }
});
도움이 되었습니까?

해결책

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

다른 팁

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){
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top