光滑的缩略图滑块当前更改缩略图焦点需要悬停

Posted

技术标签:

【中文标题】光滑的缩略图滑块当前更改缩略图焦点需要悬停【英文标题】:Slick thumbnail slider currently change on thumbnail focus need on hover as well 【发布时间】:2021-01-10 08:22:29 【问题描述】:

大家好。再会。我尝试过光滑的滑块来制作滑块动画。我想在其缩略图悬停时更改主图像。我想问这可能吗?我在 codepen 链接 (codepan) 中添加了我的代码,所以请检查此链接。提前致谢。试试这个链接,因为它显示错误,所以我分享我的代码。

jQuery(document).ready(function($) 
      $('.slider-for').slick(
          slidesToShow: 1,
          slidesToScroll: 1,
          arrows: false,
          fade: true,
          asNavFor: '.slider-nav'
      );
      $('.slider-nav').slick(
          slidesToShow: 6,
          slidesToScroll: 1,

          asNavFor: '.slider-for',
          dots: false,
          focusOnSelect: true,
          responsive: [
                  breakpoint: 992,
                  settings: 
                      vertical: false,
                  
              ,
              
                  breakpoint: 768,
                  settings: 
                      vertical: false,
                  
              ,
              
                  breakpoint: 580,
                  settings: 
                      vertical: false,
                      slidesToShow: 3,
                  
              ,
              
                  breakpoint: 380,
                  settings: 
                      vertical: false,
                      slidesToShow: 2,
                  
              
          ]
      );
  );
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css'><link rel="stylesheet" href="./style.css">
 <section class="banner-section">
   <div class="container">
       <div class="vehicle-detail-banner banner-content clearfix">
           <div class="banner-slider">
               <div class="slider slider-for">
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
               </div>
               <div class="slider slider-nav thumb-image">
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
               </div>
           </div>
       </div>
   </div>
</section>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js'></script><script  src="./script.js"></script>

【问题讨论】:

【参考方案1】:

您好,是的,您可以更改一个悬停在缩略图上的光滑滑块。您可以调用鼠标悬停功能到您的滑滑梯。创建一个条件,如果鼠标悬停在 slick nav(thumbnail) 上,则更改当前活动的目标。希望这会帮助你。我编辑了你的代码。

jQuery(document).ready(function($) 
      $('.slider-for').slick(
          slidesToShow: 1,
          slidesToScroll: 1,
          arrows: false,
          fade: true,
          asNavFor: '.slider-nav'
      );
      //set active class to first slide
$('.slider-nav .slick-slide').eq(0).addClass('slick-active');
      $('.slider-nav').slick(
          slidesToShow: 6,
          slidesToScroll: 1,

          asNavFor: '.slider-for',
          dots: false,
          focusOnSelect: true,
          responsive: [
                  breakpoint: 992,
                  settings: 
                      vertical: false,
                  
              ,
              
                  breakpoint: 768,
                  settings: 
                      vertical: false,
                  
              ,
              
                  breakpoint: 580,
                  settings: 
                      vertical: false,
                      slidesToShow: 3,
                  
              ,
              
                  breakpoint: 380,
                  settings: 
                      vertical: false,
                      slidesToShow: 2,
                  
              
          ]
      );
      $('.slider-nav').on('mouseover', '.slick-slide', function (e) 
        var $currTarget = $(e.currentTarget), 
        index = $currTarget.data('slick-index'),
        slickObj = $('.slider-for').slick('getSlick');
    
    slickObj.slickGoTo(index);
    
);
  );
.banner-slider .slider.slider-for 
    max-width: 100%;

.banner-slider .slider.slider-nav 
    max-width: 100%;

.banner-slider .slider.slider-for,
.banner-slider .slider.slider-nav 
    width: 100%;

.banner-slider .slider.slider-for
    padding: 0 5px;

.banner-slider .slick-slide img 
    width: 100%;

.banner-slider .slider-banner-image 
    height: auto;
    width: 100%;

.banner-slider .slider.slider-nav 
    padding: 20px 0 0;

.banner-slider .slider-nav .slick-slide.thumbnail-image .thumbImg img 
    height: 100%;
    width:100%;
    object-fit: cover;

.banner-slider .slider-banner-image img 
    width: 100%;
    height: 350px;
    object-fit: cover;

.banner-slider .slick-vertical .slick-slide:active,
.banner-slider .slick-vertical .slick-slide:focus,
.banner-slider .slick-arrow:hover,
.banner-slider .slick-arrow:focus 
    border: 0;
    outline: 0;

.banner-slider .slider-nav .slick-slide.slick-current span 
    color: #196DB6;

.banner-slider .slider-nav .slick-slide 
    text-align: center;

.banner-slider .slider-nav .slick-slide span 
    font-size: 14px;
    display: block;
    padding: 5px 0 15px;

.banner-slider .slick-arrow 
    width: 100%;
    background-color: transparent;
    border: 0;
    background-position: center;
    background-repeat: no-repeat;
    font-size: 0;
    height: 18px;
    position: absolute;
    left: 0;
    right: 0;
    z-index: 99;

.slick-prev 
   top: 0;

.slick-next 
   bottom: 0;
   background-color: #fff;

.banner-slider .slider.slider-nav .thumbImg 
    padding: 0 5px 15px;

.slider-nav .slick-slide.slick-current.slick-active .thumbImg img 
    border: 1px solid #80D6CF;
    border-radius: 2px;
    background-color: #FFFFFF;
    box-shadow: 0 0 2px 0 rgba(0,0,0,0.1), 0 2px 4px 0 rgba(0,0,0,0.1);
    padding: 3px;

@media screen and (max-width : 991px) 
    .banner-slider .slider.slider-for,
    .banner-slider .slider.slider-nav 
        max-width: 100%;
        float: none;
    
    .banner-slider .slider.slider-for 
        padding-right: 0;
    
    .banner-slider .slider.slider-nav 
        height: auto;
    
    .slider-banner-image 
        height: 500px;
    
    .slider.slider-nav.thumb-image 
        padding: 10px 30px 0;
    
    .slider-nav .slick-slide span 
        padding: 5px 0;
    
    .slick-arrow 
        padding: 0;
        width: 30px;
        height: 30px;
        top: 50%;
        bottom: 0;
        -webkit-transform: translateY(-50%) rotate(-90deg);
        -moz-transform: translateY(-50%) rotate(-90deg);
        -ms-transform: translateY(-50%) rotate(-90deg);
        transform: translateY(-50%) rotate(-90deg);
    
    .slick-prev 
        left: 0;
        right: unset;
    
    .slick-next 
        left: unset;
        right: 0;
        background-color: transparent;
    
    .vehicle-detail-banner .car-slider-desc 
        max-width: 340px;
    
    .bid-tag 
        padding: 10px 0 15px;
    
    .slider.slider-nav.thumb-image 
       white-space: nowrap;
    
    .thumbnail-image.slick-slide 
        padding: 0px 5px;
        min-width: 75px;
        display: inline-block;
        float: none;
    


@media screen and (max-width : 767px) 
    .slider-banner-image 
        height: 400px;
    
    .slider.slider-nav.thumb-image 
        padding: 0px 20px 0;
        margin: 10px 0px 0;
    
    .slider-nav .slick-slide.thumbnail-image .thumbImg 
        max-width: 140px;
        height: 80px;
    
    .slick-prev.slick-arrow 
        background-position: center 10px;
    
    .slick-next.slick-arrow 
        background-position: center 10px, center;
    
    .slider-nav .slick-slide span 
        font-size: 12px;
        white-space: normal;
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<section class="banner-section">
   <div class="container">
       <div class="vehicle-detail-banner banner-content clearfix">
           <div class="banner-slider">
               <div class="slider slider-for">
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                   </div>
                   <div class="slider-banner-image">
                       <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                   </div>
               </div>
               <div class="slider slider-nav thumb-image">
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570942872213-1242607a35eb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1570171278960-d6c2b316f3b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" >
                       </div>
                   </div>
                   <div class="thumbnail-image">
                       <div class="thumbImg">
                           <img src="https://images.unsplash.com/photo-1564376130023-5360fbb7c91b?ixlib=rb-1.2.1&auto=format&fit=crop&w=724&q=80" >
                       </div>
                   </div>
               </div>
           </div>
       </div>
   </div>
</section>

【讨论】:

如果它对你有用,然后将其标记为你的答案,这样其他人就不会给出任何答案 我该怎么做? ibb.co/R0Mg4XZ 你可以在给定的链接中查看图片 你可以在这个答案的左上方找到它 请同时标记为您的问题的答案,以便您的问题被标记为已解决。单击该标记。因此,如果任何贡献者以同样的问题提出您的问题,他可以找到这个答案。欢迎

以上是关于光滑的缩略图滑块当前更改缩略图焦点需要悬停的主要内容,如果未能解决你的问题,请参考以下文章

css 更好的woocommerce缩略图滑块单个产品页面

使用带有扭曲位置的slick.js的缩略图滑块

php LIghtSlider - 图像轮播缩略图滑块与WordPress中的ACF

缩略图区域需要 jquery 滑块

缩略图轮播,主滑块和缩略图之间的巨大差距

当鼠标悬停在没有css的标题上时,如何使缩略图消失?