garand / sticky

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

use css at certain breakpoints to disable the sticky effect #231

Open v3nt opened 8 years ago

v3nt commented 8 years ago

So on smaller screens its just part of the html flow and not 'fixed' and maybe the inline height is disabled?

reesmcivor commented 7 years ago

I have needed the same functionality, but instead of changing the CSS I decided to add a function that gets triggered on resize so that I could unstick the element.

On Line 151 below:

if (newWidth != null) {
    s.stickyElement.css('width', newWidth);
}

`s.stickyElement.trigger('sticky-resize', [s]);` // new line added

My function I attached:

$this.on('sticky-resize', function(s) {
    var w = $(window).width();
        if(w <= 320) {
            $this.sticky('unstick');
        } else if (w > 320 && w <= 768) {
             $this.sticky(options);
         } else if (w > 768 && w <= 1024) {
              $this.sticky(options);
         } else {
               $this.sticky(options);
         }
 });
mhulse commented 7 years ago

See also: #211