glide icon indicating copy to clipboard operation
glide copied to clipboard

Disable/Enable glide based on breakpoint

Open derpoho opened this issue 6 years ago • 56 comments

Hey,

thanks for this great slider, really modern coding and good execution!

I am lacking a feature i was used from slick.js.

I want to be able to disable/enable the slider/carousel based on breakpoints, as you already have the breakpoint setting and the matchMedia implemented it would make sense to add this.

See the slick docs for an example: https://github.com/kenwheeler/slick#responsive-option-example

May add the option to set a breakpoint to false and check for the boolean?

PS: I know how to do it outside of glide, but it would be nice to do it all at once ;)

Greets Marcus

derpoho avatar May 05 '18 19:05 derpoho

Hello 👋. Thanks for the suggestion.

I'm trying to keep a core functionalities to a minimum and leave all use-case specific to be done via API. I mark this as the feature and watch if there is a large interest.

jedrzejchalubek avatar May 10 '18 15:05 jedrzejchalubek

+1 on this. I use this feature all the time in Flickity. It's very useful when I want a set of elements to display 4-across on larger screens, but be able to swipe through them on mobile.

elivz avatar May 10 '18 17:05 elivz

I also have needed this functionality quite a few times in the past. display a standard row or grid of items on larger screens and then initialise the carousel once we start running out of breathing space at smaller sizes. I am currently using a combination of glideJS and Simple State Manager to achieve this in case anyone is interested

bw1984 avatar May 16 '18 09:05 bw1984

this is basically what i was attempting to describe in #208

bw1984 avatar May 16 '18 09:05 bw1984

+1

Abby805 avatar Jun 04 '18 14:06 Abby805

Finally left Slick behind in part because their breakpoint feature is broken / doesn't work as most would intend it to out-of-the-box. Would love to see initialize-at-breakpoint implemented in the core functionality here, and I'm sure many others finally upgrading to Glide would too. Thanks!

mandynicole avatar Jul 17 '18 23:07 mandynicole

+1!

A workaround for this would just be destroying and re-initializing on a throttled window resize but please add this soon!

markjoeljimenez avatar Aug 16 '18 21:08 markjoeljimenez

+1

AndyWilson82 avatar Sep 04 '18 19:09 AndyWilson82

+1 Would love to have this. I know glide.js is about having as light a library as possible, but look at flickity, they have a css :: after check that activates the carousel. Would love to have that as an API

Arbust908 avatar Oct 10 '18 19:10 Arbust908

+1 - essentially need the functionality of #208. Carousel content is loaded via a CMS so number of images is indeterminate. Glide duplicates slides to fill the space up to the perView which isn't ideal. The solution would be to not mount it, but then when it responds to smaller screen sizes it does need to be mounted.

brentkelly avatar Nov 13 '18 23:11 brentkelly

Another +1 - Started commenting on https://github.com/glidejs/glide/issues/208, but realise this is basically the same feature request.

matt-bailey avatar Mar 07 '19 11:03 matt-bailey

Another +1

sl-pascalgeay avatar Mar 20 '19 08:03 sl-pascalgeay

1+ ;)

mediabeastnz avatar Apr 01 '19 02:04 mediabeastnz

+1 here too. Like others, I'm trying to drop slick and honestly Glide is so nice to work with I'm happy to figure out a workaround as suggested in the comments in this thread. However it would be awesome to have this feature in core :)

Essk avatar Apr 25 '19 14:04 Essk

+1

Badyanchik avatar May 06 '19 12:05 Badyanchik

+1

evzaro avatar May 14 '19 14:05 evzaro

+1 this is a must. We use carousels about 50% of time just to keep columns next to each other on mobile devices to reduce body height, so it would be nice to not init it when there is enough space.

martinsnajdr avatar May 21 '19 10:05 martinsnajdr

Definitely a necessary feature, migrated from Slick which had this ability. When you have a layout that moves to sliders on mobile widths it's super important. EDIT: For anyone looking for a quick-ish solution, this can be achieved by just removing all of the glide specific classes on a breakpoint in your JS, calliing .destroy() on the slider object, and then just doing the opposite whenever you want it initialized again.

propagandaCreative avatar May 21 '19 17:05 propagandaCreative

+1

Jan10 avatar Jul 25 '19 12:07 Jan10

+1

TomDeSmet avatar Aug 09 '19 08:08 TomDeSmet

+1

marisaroque avatar Aug 12 '19 16:08 marisaroque

+1, will switch over to use this, if implemented.

philip-keep avatar Aug 16 '19 01:08 philip-keep

+1 as a workaround I created this function to help me at the moment. ` var glide = new Glide('.glide') var stateBreakpoint = 768;

//Initial glide state
glideState(getWindowWidth(), glide, stateBreakpoint);

//On glide resize glide state
glide.on('resize', function() {
    glideState(getWindowWidth(), glide, stateBreakpoint);
});

/**
    * getWindowWidth
    * 
    * Gets the width of the current html document using the css property
    *
    * @return {int}
    */
    function getWindowWidth(){
    return parseInt($('html').css('width'));
}

/**
    * glideState
    *
    * Sets the state of the glide slider depending on breakpoint
    *
    * @param {string} width
    * @param {object} glide
    * @param {int} breakpoint
    * @return {void}
    */
function glideState(width, glide, breakpoint){
    if (width < breakpoint){
        glide.enable();
    }else{
        glide.disable()
    }
}`

davygxyz avatar Aug 19 '19 17:08 davygxyz

+1 this feature would be super useful

maxhartshorn avatar Aug 19 '19 20:08 maxhartshorn

I found a pretty good solution, using SimpleStateManager. In my case i got a grid which displays divs in rows and columns. But if the viewport reaches a maximum of 768px the grid switches to a slider. Here is my code:

  var panels;
  ssm.addState({
    id: "mobile",
    query: "(max-width: 1110px)",
    onEnter: function() {
      panels = new Glide("#panels", {
        type: "carousel",
        startAt: 0,
        perView: 2.25,
        gap: 0,
        bound: true,
        breakpoints: {
          768: {
            perView: 1.25
          }
        }
      })
      panels.mount()
    },
    onLeave: function() {
      panels.destroy()
    }
  });

Obviously the slider gets destroyed and the divs get reverted to rows and columns if the viewports reaches over 768px;

I hope this is helpful for someone!

fv-enrico avatar Aug 23 '19 08:08 fv-enrico

Adding pointer-events: none; to the parent element for small screens did the trick for me.

Edit: Just wanted to disable slides in small screen and use slide buttons instead

the94air avatar Oct 03 '19 16:10 the94air

Another vote for this feature! I was looking to replace Flickity with this.

danimalweb avatar Nov 28 '19 23:11 danimalweb

+1, regret using the slider now that I know this feature isn't supported..

nataliawww avatar Jan 03 '20 10:01 nataliawww

+1, need it everytime

riderodd avatar Jan 06 '20 17:01 riderodd

+1 need this for a new project to stack columns on mobile + disable glide

alexcapes avatar Jan 31 '20 09:01 alexcapes