最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make slick carousel full screen? - Stack Overflow

programmeradmin3浏览0评论

I'm trying to make a carousel take up the entire screen, nothing I'm trying seems to work...

  $('.scroller').slick({
    dots: true,
    infinite: true,
    autoplay: true
  })
.scroller {
  div {
    text-align: center;
    font-size: 30px;
    max-height: 100%;
  }
}

.slick-prev::before, .slick-next::before {
  color: #000;
}

.slick-next {
  right: -5px;
}

.slick-prev {
  left: -5px;
}
<div class="scroller">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

I'm trying to make a carousel take up the entire screen, nothing I'm trying seems to work...

  $('.scroller').slick({
    dots: true,
    infinite: true,
    autoplay: true
  })
.scroller {
  div {
    text-align: center;
    font-size: 30px;
    max-height: 100%;
  }
}

.slick-prev::before, .slick-next::before {
  color: #000;
}

.slick-next {
  right: -5px;
}

.slick-prev {
  left: -5px;
}
<div class="scroller">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

setting the max height to 100% did nothing to fix it. It is currently only covering about one third of the page

Share Improve this question edited Apr 11, 2016 at 17:53 Wowsk 3,6752 gold badges19 silver badges30 bronze badges asked Apr 11, 2016 at 17:08 ncrouch25ncrouch25 2702 gold badges4 silver badges12 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

You can set the height of the scroller dynamically to the height of the screen with JQuery:

$(document).ready(function(){
  $('.scroller').css('height', $(window).height() + 'px');
});

In css....

Make your slick container...

height: 100vh;

then make sure BOTH:

the child element of your slick container with class .slick-track

AND

your slide elements

have height: 100%;

You can use this function.

var elem = document.getElementByClassName("scroller")[0];
if (elem.requestFullscreen) {
  elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
  elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
  elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
  elem.webkitRequestFullscreen();
}
发布评论

评论列表(0)

  1. 暂无评论