garand / sticky

jQuery Plugin for Sticky Objects
Other
3.3k stars 1.06k forks source link

Good plugin, but.. unable to unstick when reach the footer #256

Open mkaizumi opened 7 years ago

mkaizumi commented 7 years ago

I was thinking how to unstick when sticker just reach the footer, I don't want the sticker is overlapping or get behind it and just slide it away.. anyone know how to unstick the sticker before is reach footer? thanks

ao commented 7 years ago

Wondering how to do this myself. Any thoughts?

Arpsara commented 7 years ago

@ao @mkaizumi Hi! In case you didn't figured it out, I managed to do it by doing something like this:


  # When scrolling
  $(window).scroll( () ->
    # Get window position
    # console.log $(window).scrollTop()
    position = 123 # OR  position = $("#myDiv").offset().top
    if ($(window).scrollTop() >position )
      $("#sticky").unstick()
    else
      $("#sticky").sticky()
  )

You can have a look at this stackoverflow answer https://stackoverflow.com/questions/13522971/jquery-to-detect-scrolling-div-position

Hope it helps! :)

saruban commented 7 years ago

I tried to add it to my script but not working. Please check this.

Arpsara commented 7 years ago

@saruban I think you have to rewrite it in javascript (it's coffeescript here! :) )

saruban commented 7 years ago

Can you please help me to rewrite it on js. :)

On 1 Aug 2017 17:39, "Arpsara" notifications@github.com wrote:

@saruban https://github.com/saruban I think you have to rewrite it in javascript (it's coffeescript here! :) )

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/garand/sticky/issues/256#issuecomment-319352037, or mute the thread https://github.com/notifications/unsubscribe-auth/AJiowYed1fTUOej4b3wbtzfOlGP9wHRLks5sTxWSgaJpZM4NUms3 .

ao commented 7 years ago

@saruban

$(window).scroll(function() {
  var position;
  position = 123;
  if ($(window).scrollTop() > position) {
    return $("#sticky").unstick();
  } else {
    return $("#sticky").sticky();
  }
});
saruban commented 7 years ago

Thank you so much. Will Check and back to you. :)

On 1 Aug 2017 6:24 pm, "Andrew Odendaal" notifications@github.com wrote:

@saruban https://github.com/saruban

$(window).scroll(function() { var position; position = 123; if ($(window).scrollTop() > position) { return $("#sticky").unstick(); } else { return $("#sticky").sticky(); } });

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/garand/sticky/issues/256#issuecomment-319361493, or mute the thread https://github.com/notifications/unsubscribe-auth/AJiowR4hR8hCp4dVEK94VT4uFXFLHyDMks5sTx_wgaJpZM4NUms3 .

naho2081 commented 7 years ago

You don't need to unstick.

Proper way is to determine "bottomSpacing" value correctly based on the height of the footer that can be variable in some cases.

Just add dummy divs on the page with div(id="contentEnd") - where main page content ends and starts footer div(id="pageEnd") - at the end of the footer

And then initialize Sticky plugin

bottomSpacing = $("#pageEnd").offset().top - $("#contentEnd").offset().top
$('#sticky').sticky
    topSpacing: 100
    bottomSpacing: bottomSpacing
kytosai commented 6 years ago

You can view more detail how to pause sticky when reach destination point - https://github.com/garand/sticky/issues/257#issuecomment-351935092

jeremy-hawes commented 6 years ago

Another option that worked a little better in my situation

    var footerBottomAdjust = $('#footer').height() + 50;
    $('#sticky').sticky({
        topSpacing: 200,
        bottomSpacing: footerBottomAdjust
    });
itsKnight847 commented 6 years ago

@jeremy-hawes tyvm!