Slick Scroller JS Carousel拉伸中心div以填满整个窗口

时间:2016-11-13 23:36:26

标签: jquery css carousel slick.js scroller

我遇到了一个我无法解释的问题。我有Slick设置显示3个幻灯片,centerMode为true和draggable。它很棒。我将光滑滚动条的整个容器div设置为在移动视图(480px及以下或其周围的某些位置)显示无,然后只在块模式下显示图像,居中,这很好。但是,我希望平板电脑上的用户仍可以看到Slick Scroller。问题是,当在平板电脑上加载页面时,Slick Scroll轮播只显示最中心的Div(图像),如果它没有填满容器的整个宽度,它会不成比例地拉伸它以填充它。它仍然滚动,但外观可怕。我不明白是什么导致这种情况,因为在桌面上重新调整窗口大小不会产生任何问题。

这是该网站的实际应用。正如您所看到的,它在浏览器上工作正常(无论您想要调整大小),但是如果您在平板电脑上加载,它会扭曲图像并希望Div聚焦以100%填充容器宽度......

http://philippenewman.com/photography/

$(document).on('ready', function () {
	$(".variable").slick({
		infinite: true,
		variableWidth: true,
		slidesToShow: 3,
		draggable: true,
		centerMode: true,
		swipeToSlide: true
	});
});
html,  body {
	margin: 0;
	padding: 0;
}
* {
	box-sizing: border-box;
}
.slider {
	width: 90%;
	margin: 0 auto;
	margin-top: 100px;
}
.slick-slide {
	margin: 0px 20px;
}
.slick-slide img {
	width: 100%;
	height: 700px;
	max-height: 80vh;
}
.slick-prev:before,  .slick-next:before {
	color: white;
}
<!DOCTYPE html>
<html>
<head>
<title>Slick Playground</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./css/slick/slick.css">
<link rel="stylesheet" type="text/css" href="./css/slick/slick-theme.css">

<!-- External Stylesheets-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- External Stylesheets-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!--  Jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<!-- Latest compiled and minified Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<!-- Stylesheets-->
<link rel="stylesheet" href="./css/style.css" type="text/css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<!-- Stylesheets-->
<link rel="stylesheet" href="./css/style.css" type="text/css">
</head>

<body>

<!--BEGIN NAVBAR-->
<nav class="navbar navbar-inverse navbar-fixed-top navbar-custom">
  <div class="container-fluid"> 
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
      <a class="navbar-brand" href="index.html">philippe newman <span style="color:#99b3ff">photography</span></a> </div>
    
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Galleries <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="sanfrancisco.html">San Francisco</a></li>
            <li><a href="#">California</a></li>
          </ul>
        </li>
        <li> <a href="process_production.html">process + production</a> </li>
        <li> <a href="contact.html">Contact</a> </li>
      </ul>
    </div>
    <!-- /.navbar-collapse --> 
  </div>
  <!-- /.container-fluid --> 
</nav>
<!--END NAVBAR--> 

<!--   BEGIN MAIN CONTENT HERE-->
<main class="main"> 
  
  <!--       This section is for large tablet/Desktop views-->
  <section class="variable slider hidden-xs">
    <div> <img src="./images/photography/san_francisco/caltrain_lights_9_7_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/embarcadero_sunset_10_7_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/golden_gate_bridge_dusk_10_10_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/mission_st_alley_graffiti_san_francisco_8_26_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/metreon_sf_intersection_night_8_13_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/marshal_beach_sunset_second_10_19_2016.jps" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/cathedral_of_st_mary_san_francisco_7_20_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/sf_windmill_night_9_30_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/sutro_baths_sunset_second_shot_6_18_2016.jpg" class="img-responsive"> </div>
    <div> <img src="./images/photography/san_francisco/seacliff_sunset_6_21_2016.jpg" class="img-responsive"> </div>
  </section>
  
  <!--        This section is for our mobile/tablet view only-->
  <section class="mobile-gallery hidden-sm hidden-md hidden-lg">
    <div class="container">
      <div class="row">
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/caltrain_lights_9_7_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/embarcadero_sunset_10_7_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/golden_gate_bridge_dusk_10_10_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/mission_st_alley_graffiti_san_francisco_8_26_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/metreon_sf_intersection_night_8_13_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/marshal_beach_sunset_second_10_19_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/cathedral_of_st_mary_san_francisco_7_20_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/sf_windmill_night_9_30_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/sutro_baths_sunset_second_shot_6_18_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
        <div class="col-xs-12 photo-row"> <img src="./images/photography/san_francisco/seacliff_sunset_6_21_2016_thumbnail.jpg" class="img-responsive center-block"> </div>
      </div>
    </div>
  </section>
</main>
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script> 
<!--    JS file for Slick Scroller carousel--> 
<script src="./js/slick/slick.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

fiddle link

1 个答案:

答案 0 :(得分:0)

想出来。

将宽度更改为自动。

显然,在Slider内的每个Image标签上max-height设置为80vh,宽度设置为100%,在桌面浏览器(至少是firefox)上它呈现得很好,尽管实际上包含Slider Div没有定义的宽度,而在Mobile上它将100%作为完整的Slick容器100%渲染。

保持高度CSS原样,然后设置width:auto;为桌面和移动设备分类。