首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OwlCarousel缩略图

OwlCarousel缩略图
EN

Stack Overflow用户
提问于 2017-12-22 02:55:47
回答 1查看 7.3K关注 0票数 0

因此,我创建了一个图像转盘,然后为其缩略图创建了另一个转盘,因为缩略图与转盘中的图像不同。现在我的问题是,当试图通过单击缩略图来更改图像时。

对于缩略图函数,我使用这个插件:https://github.com/gijsroge/OwlCarousel2-Thumbs

下面是我的设置:

代码语言:javascript
复制
<div class="owl-carousel main-carousel" data-slider-id="1">
    <div>Your Content</div>
    <div>Your Content</div>
    <div>Your Content</div>
    <div>Your Content</div>
</div>
<div class="owl-thumbs owl-carousel" data-slider-id="1">
    <button class="owl-thumb-item">slide 1</button>
    <button class="owl-thumb-item">slide 2</button>
    <button class="owl-thumb-item">slide 3</button>
    <button class="owl-thumb-item">slide 4</button>
</div>
EN

回答 1

Stack Overflow用户

发布于 2018-07-12 22:11:27

你的答案在这里链接:https://codepen.io/olgaysezgin/pen/JBdrxE

代码语言:javascript
复制
$(document).ready(function() {
  $(".owl-carousel").owlCarousel({

    items: 1,


  });
});


// the following to the end is whats needed for the thumbnails.
jQuery(document).ready(function() {


  // 1) ASSIGN EACH 'DOT' A NUMBER
  dotcount = 1;

  jQuery('.owl-dot').each(function() {
    jQuery(this).addClass('dotnumber' + dotcount);
    jQuery(this).attr('data-info', dotcount);
    dotcount = dotcount + 1;
  });

  // 2) ASSIGN EACH 'SLIDE' A NUMBER
  slidecount = 1;

  jQuery('.owl-item').not('.cloned').each(function() {
    jQuery(this).addClass('slidenumber' + slidecount);
    slidecount = slidecount + 1;
  });

  // SYNC THE SLIDE NUMBER IMG TO ITS DOT COUNTERPART (E.G SLIDE 1 IMG TO DOT 1 BACKGROUND-IMAGE)
  jQuery('.owl-dot').each(function() {

    grab = jQuery(this).data('info');

    slidegrab = jQuery('.slidenumber' + grab + ' img').attr('src');
    console.log(slidegrab);

    jQuery(this).css("background-image", "url(" + slidegrab + ")");

  });

  // THIS FINAL BIT CAN BE REMOVED AND OVERRIDEN WITH YOUR OWN CSS OR FUNCTION, I JUST HAVE IT
  // TO MAKE IT ALL NEAT 
  amount = jQuery('.owl-dot').length;
  gotowidth = 100 / amount;

  jQuery('.owl-dot').css("width", gotowidth + "%");
  newwidth = jQuery('.owl-dot').width();
  jQuery('.owl-dot').css("height", newwidth + "px");



});
代码语言:javascript
复制
html {
  height: 100%;
  width: 100%;
}

.slide-cont {
  width: 600px;
  display: block;
  margin: 0 auto;
}

.owl-carouse div {
  width: 100%;
}


/*SEE END OF THUMBNAIL FUCNTION TO TINKER SIZE OF THUMBS*/

.owl-carousel .owl-controls .owl-dot {
  float: left;
  background-size: cover;
  margin-top: 10px;
}


/* BELOW THIS IS JUST MY OWN BACKGROUND ETC AND ISN'T NEEDED */

body {
  background-color: #1f1f1f;
  background: -webkit-radial-gradient(#1f1f1f, #000000);
  background: radial-gradient(#1f1f1f, #000000);
}

h1 {
  font-family: 'Open Sans', sans-serif;
  font-size: 30px;
  color: #fff;
  text-align: center;
  position: absolute;
  width: 100%;
  top: 0px;
  background: #000;
  margin: 0px;
  padding: 15px 0px;
  z-index: 200;
}

.owl-carousel .owl-dot {
  float: left;
  background-size: cover;
}
代码语言:javascript
复制
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.6/owl.carousel.min.js"></script>
  <!-- STYLE FOR H1 TAG -->
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:700' rel='stylesheet' type='text/css'>
  <!-- ESSENTIAL OWL CARO CSS FILE -->
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.6/assets/owl.carousel.min.css">
</head>

<h1>Owl Carousel 2 Thumbnails</h1>


<div class="slide-cont">
  <div class="owl-carousel">
    <div><img src="http://imew.co.uk/wp-content/uploads/2017/03/cav1-1.png"></div>
    <div><img src="http://imew.co.uk/wp-content/uploads/2017/03/cav2-1.png"></div>
    <div><img src="http://imew.co.uk/wp-content/uploads/2017/03/cav3-1.png"></div>
    <div> <img src="http://imew.co.uk/wp-content/uploads/2017/03/cav4-1.png"></div>
    <div> <img src="http://imew.co.uk/wp-content/uploads/2017/03/cav4-1.png"></div>
  </div>
</div>

<!--
Copyright (c) 2018 by Olgay Sezgin (https://codepen.io/olgaysezgin/pen/JBdrxE)
Fork of an original work by Martin Whitaker (https://codepen.io/sirnightowl/pen/JoJwrE)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47931108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档