Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

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

Open
mkaizumi opened this issue May 8, 2017 · 11 comments
Open

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

mkaizumi opened this issue May 8, 2017 · 11 comments

Comments

@mkaizumi
Copy link

mkaizumi commented May 8, 2017

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

@mkaizumi mkaizumi changed the title Good plugin, but.. unstick when reach the footer Good plugin, but.. unable to unstick when reach the footer May 8, 2017
@ao
Copy link

ao commented Jun 12, 2017

Wondering how to do this myself. Any thoughts?

@Arpsara
Copy link

Arpsara commented Jun 23, 2017

@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
Copy link

saruban commented Aug 1, 2017

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.sticky/1.0.4/jquery.sticky.js"></script> <script> jQuery( document ).ready(function() { jQuery("#stick-form-prv").sticky({topSpacing:645}); jQuery("#stick-form").sticky({topSpacing:290}); jQuery("#stick-form-img").sticky({topSpacing:180}); jQuery("#stick-form-btn").sticky({topSpacing:115}); }); # 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() ) </script>

@Arpsara
Copy link

Arpsara commented Aug 1, 2017

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

@saruban
Copy link

saruban commented Aug 1, 2017 via email

@ao
Copy link

ao commented Aug 1, 2017

@saruban

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

@saruban
Copy link

saruban commented Aug 1, 2017 via email

@naho2081
Copy link

naho2081 commented Sep 9, 2017

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
Copy link

kytosai commented Dec 15, 2017

You can view more detail how to pause sticky when reach destination point - #257 (comment)

@jeremy-hawes
Copy link

Another option that worked a little better in my situation

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

@itsKnight847
Copy link

@jeremy-hawes tyvm!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants