Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto hide scrollbar #306

Open
marijnruijl opened this issue May 17, 2021 · 3 comments
Open

Auto hide scrollbar #306

marijnruijl opened this issue May 17, 2021 · 3 comments

Comments

@marijnruijl
Copy link

marijnruijl commented May 17, 2021

I would like the scrollbar to be automatically hidden when there is not enougth items to scroll. Is this possible?

My code ->
Carousel.txt

@ghtali
Copy link

ghtali commented May 17, 2021

You may set a limit or just define a condition, something like this:

if (items.length <= 1) { scrollBar: $wrap.find('') }else scrollBar: $wrap.find('.scrollbar')

@marijnruijl
Copy link
Author

Thanks, I have create a solution with query and css:

$(document).ready(function(){
if ($(".projectbox.slidee:nth-child(4)").hasClass("slidee")) {
$(".scrollbar").addClass('show-me-the-button');
} else {
$(".scrollbar").removeClass('show-me-the-button');
}
});

@sjankowski
Copy link

sjankowski commented Aug 26, 2021

I came up with this function to check if children elements are overflowing the container:

 function checkOverflow (el) {
      var curOverflow = el.style.overflow
      if (!curOverflow || curOverflow === 'visible')
        el.style.overflow = 'hidden'
      var isOverflowing =
        el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight
      el.style.overflow = curOverflow
      return isOverflowing
    }

Then you can use it like:

  `let overflowed = checkOverflow(document.querySelector('.frame'));
    if (overflowed) {
        var scrollbar = $wrap.find('.scrollbar')
    } else {
        var scrollbar = 0;
        $wrap.find('.scrollbar').remove();
    }`

and then use scrollbar variable as value for ScrollBar option:
scrollBar: scrollbar

Hope it helps someone :)

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

No branches or pull requests

3 participants