Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

I've created a slider plugin that responds directly to css input

Featured Replies

It's called 'Block-slider' not very original I know, I've never been very good at naming things, anyway there's thousands of very capable sliders out in the wild, and in many cases sliders are not great in terms of UX and conversion yada yada..

 

On a project I was working on however I had a very specific use case, but one that I've come across numerous times..

 

We had a list of company logos, companies our client has worked with - there's 9 of them in total, that number could increase or decrease via the CMS and rather than put them tiled layout, I wanted them to all remain on a single row and not to tile at smaller screens.

 

This has a few issues

  • At very small screens the logos will be too small
  • We can't set % width columns that will fit on a single row without knowing the number of items.

So I built this slider that enables this.

You can use CSS to dictate how many logos to be visible in the screen at any given moment using media querys and % widths on the items - if you have 12 items and you set the width to 25% you will have 4 visible items, with a total of 3 slides.

You can alternatively use whatever responsive grid system you are using on the items to set the widths.

 

The slider slides one item at a time as opposed to an entire slide. On a screen resize event the slider resets to the beginning and readjusts to the new item dimensions.

 

You can control the interval and transition timing and classnames easily via the API. There are no user controls for this slider as the use case is very specific and I wanted the code to remain minimal (2.1k minified)

 

It does not require jQuery or any other library, however if it detects jQuery's presence it will register itself as a plugin.

 

You can see a quick demo I put up here: http://codepen.io/rbrtsmith/pen/ZbeXqa

 

And read more about how to use this in the repository on GitHub https://github.com/rbrtsmith/BlockSlider

 

There is a bug that I'm working to fix in Safari, but as yet I've had no luck, if anybody fancies lending a hand with testing out the issue in safari please feel free to do so :)

  • Author

 

What's the bug exactly?

 

Edit: argh, annoying!

 

You saw it! when screen resizes it miscalculates the widths.

Really strangely when I add a debugger breakpoint and step through it in Safari everything works, even when you resize the screen. Remove the breakpoint and it bugs! very very odd.

Like I say Safari the new IE. Even in IE9 it worked first time!

  • Author

I think I've fixed the Safari bug, it seems that Safari takes longer to complete a layout, and my calculations on safari were running too early.

So I've had to add in a delay for Safari of 500ms on the screen resize event.. It's a bit hacky, but I've tried to make it as painless as possible by hiding the slider momentarily when the screen resizes. I've also improved the resize function, going from a debounce to only being called once the screen has ceased resizing.

Thankfully there's no such delay on the decent browsers.

Edited by rbrtsmith

  • Author

Looks great! Well done! :)

 

Thanks. Down to 1.8kb now too :)

 

But upto 2.5k as I added a load of error handling, that logs out useful warnings to the console and allows the module to fail gracefully.

Edited by rbrtsmith

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.