2016-01-07 3 views
5

Ich versuche, ein benutzerdefinierte vertikale Bild Karussell zu erstellen, weil ich keine Plugins da draußen aufgrund der js Ereignisse an die Bilder, die ich beibehalten muss und die einzige Möglichkeit, die würde verwenden würde Arbeit für mich ist es, benutzerdefinierte Karussell zu erstellen.Erstellen Sie ein vertikales Bild Karussell

Funktionalitäten

  • Bild Karussell hat gleich 3 Größen im Ansichtsfenster haben.
  • Das Bildkarussell hat die nächste/vorherige Schaltfläche, mit der Sie weitere Bilder anzeigen/auswählen können.
  • Die nächste/vorherige Schaltfläche lässt nur einen Schritt zu einem Zeitpunkt zu, dh, es wird nicht die nächste Gruppe von Bildern ausgewählt und im Ansichtsfenster angezeigt.

enter image description here

  • Karussell bietet Ihnen alle Bilder im Ansichtsfenster auszuwählen, und dies wird synchronisieren, wenn die nächste/Prev Taste
geklickt wird

enter image description here

Alle Funktionalitäten oben aufgeführten ist bereits implementiert.

PROBLEM

Das letzte Bild wird vor der nächsten Taste nicht Snap/Stopp, da es Leerzeichen dazwischen schaffen.

enter image description hereenter image description here

JS-Code

$(function(){ 
     var image_height = 0; 
     var gallery_offset = 0; 
     var image_count = $('img.thumbnail').length; 
     var click_count = 0; 
     var image_height = 0; 
     var last_images_count = 0; 

     $('.gallery-container a').click(function(){ 
      $('.gallery-container a').removeClass('active') 
      $(this).addClass('active'); 

     }); 

     jQuery('.thumbnail').each(function(){ 
      $(this).on('load', function(){ image_height = $(this).parent().outerHeight(); }); 
      image_height = $(this).parent().outerHeight(); 
     }) 

     // Disable arrows if the images count is 3 below 
     if(image_count <= 3) { 
      $('.product-more-pictures .up, .product-more-pictures .down').addClass('disabled') 
      click_count = 0; 
     } 

     // Set the first image as active 
     jQuery('.gallery-container img.thumbnail').first().click(); 
     var thumb_active = jQuery('.gallery-container .active'); 

     $('.gallery-container a').on('click', function() { 
      thumb_active = jQuery('.gallery-container .active'); 
     }); 

     $('.product-more-pictures .down').on('click', function (e) { 
      $('.product-more-pictures .up').removeClass('disabled') 
      if(thumb_active.nextAll(':lt(1)').length) { 
       thumb_active.nextAll(':lt(1)').children().click() 
       thumb_active = jQuery('.gallery-container .active'); 

      } 

      if(! thumb_active.next().length) { 
       $(this).addClass('disabled') 
      } else { 
       $(this).removeClass('disabled'); 
      } 

      if (click_count < image_count) { 
       click_count = click_count + 1; 

       update_gallery('down'); 
      } 



     }); 

     $('.product-more-pictures .up').on('click', function() { 
      $('.product-more-pictures .down').removeClass('disabled') 
      if(thumb_active.prevAll(':lt(1)').length) { 
       thumb_active.prevAll(':lt(1)').children().click() 
       thumb_active = jQuery('.gallery-container .active'); 
      } 

      if(! thumb_active.prev().length) { 
       $(this).addClass('disabled') 
      } else { 
       $(this).removeClass('disabled'); 
      } 

      if (click_count > 0) { 
       click_count = click_count - 1; 

       update_gallery('up'); 

      } 
     }); 

     function update_gallery(direction) {   
      gallery_offset = click_count * image_height; 
      last_images_count = thumb_active.nextAll().length; 

      $(".gallery-container").animate({ 
       'top': '-' + gallery_offset + 'px' 
      }, 800); 

     } 

}); 

Fiddle: https://jsfiddle.net/qrvrdjch/6/

Jede Hilfe wäre sehr geschätzt :)

Antwort

5

Try this .. . Sie müssen die Anzahl der Klicks als -1 initialisieren, und ändern Sie die if (click_count < image_count) auf diese "if (click_count < image_count - 3)" seit dem Laden standardmäßig ausgewählte Bild ist zuerst, so wird dieses Ihr Bedarf I erraten NB: keine in CSS und HTML

$(function(){ 
    var image_height = 0; 
    var gallery_offset = 0; 
    var image_count = $('img.thumbnail').length; 
    var click_count = -1; 
    var image_height = 0; 
    var last_images_count = 0; 

    $('.gallery-container a').click(function(){ 
     $('.gallery-container a').removeClass('active') 
     $(this).addClass('active'); 

    }); 

    jQuery('.thumbnail').each(function(){ 
     $(this).on('load', function(){ image_height = $(this).parent().outerHeight(); }); 
     image_height = $(this).parent().outerHeight(); 
    }) 

    // Disable arrows if the images count is 3 below 
    if(image_count <= 3) { 
     $('.product-more-pictures .up, .product-more-pictures .down').addClass('disabled') 
     click_count = 0; 
    } 

    // Set the first image as active 
    jQuery('.gallery-container img.thumbnail').first().click(); 
    var thumb_active = jQuery('.gallery-container .active'); 

    $('.gallery-container a').on('click', function() { 
     thumb_active = jQuery('.gallery-container .active'); 
    }); 

    $('.product-more-pictures .down').on('click', function (e) { 
     $('.product-more-pictures .up').removeClass('disabled') 
     if(thumb_active.nextAll(':lt(1)').length) { 
      thumb_active.nextAll(':lt(1)').children().click() 
      thumb_active = jQuery('.gallery-container .active'); 

     } 

     if(! thumb_active.next().length) { 
      $(this).addClass('disabled') 
     } else { 
      $(this).removeClass('disabled'); 
     } 
     if (click_count < image_count - 3) { 
      console.log(image_count) 
      console.log(click_count) 
      click_count = click_count + 1; 

      update_gallery('down'); 
     } 



    }); 

    $('.product-more-pictures .up').on('click', function() { 
     $('.product-more-pictures .down').removeClass('disabled') 
     if(thumb_active.prevAll(':lt(1)').length) { 
      thumb_active.prevAll(':lt(1)').children().click() 
      thumb_active = jQuery('.gallery-container .active'); 
     } 

     if(! thumb_active.prev().length) { 
      $(this).addClass('disabled') 
     } else { 
      $(this).removeClass('disabled'); 
     } 

     if (click_count > 0) { 
      click_count = click_count - 1; 

      update_gallery('up'); 

     } 
    }); 

    function update_gallery(direction) {   
     gallery_offset = click_count * image_height; 
     last_images_count = thumb_active.nextAll().length; 

     $(".gallery-container").animate({ 
      'top': '-' + gallery_offset + 'px' 
     }, 800); 

    } 

}); 
+0

Super! Danke Manu! – Vincent

4

Sie sind fast da. Sie müssen nur eine Bedingung bearbeiten. Change "if (click_count < IMAGE_COUNT)" unter Click-Ereignis von unten-Taste (Zeile 48 in JSFiddle) auf "if (click_count < IMAGE_COUNT-3)"

$(function(){ 
 
     var image_height = 0; 
 
     var gallery_offset = 0; 
 
     var image_count = $('img.thumbnail').length; 
 
     var click_count = 0; 
 
     \t var image_height = 0; 
 
     var last_images_count = 0; 
 
     
 
     $('.gallery-container a').click(function(){ 
 
      $('.gallery-container a').removeClass('active') 
 
     \t $(this).addClass('active'); 
 
      
 
     }); 
 
     
 
     \t jQuery('.thumbnail').each(function(){ 
 
      $(this).on('load', function(){ image_height = $(this).parent().outerHeight(); }); 
 
      image_height = $(this).parent().outerHeight(); 
 
     }) 
 
     
 
     // Disable arrows if the images count is 3 below 
 
     if(image_count <= 3) { 
 
     \t $('.product-more-pictures .up, .product-more-pictures .down').addClass('disabled') 
 
      click_count = 0; 
 
     } 
 
     
 
     // Set the first image as active 
 
     jQuery('.gallery-container img.thumbnail').first().click(); 
 
     \t var thumb_active = jQuery('.gallery-container .active'); 
 
     
 
     $('.gallery-container a').on('click', function() { 
 
     \t thumb_active = jQuery('.gallery-container .active'); 
 
     }); 
 

 
     $('.product-more-pictures .down').on('click', function (e) { 
 
      \t $('.product-more-pictures .up').removeClass('disabled') 
 
      \t if(thumb_active.nextAll(':lt(1)').length) { 
 
       thumb_active.nextAll(':lt(1)').children().click() 
 
       thumb_active = jQuery('.gallery-container .active'); 
 

 
      } 
 
      
 
      if(! thumb_active.next().length) { 
 
       $(this).addClass('disabled') 
 
      } else { 
 
       $(this).removeClass('disabled'); 
 
      } 
 
      
 
      if (click_count < image_count-3) { 
 
       click_count = click_count + 1; 
 
       
 
       update_gallery('down'); 
 
      } 
 
      
 
      
 
      \t 
 
     }); 
 

 
     $('.product-more-pictures .up').on('click', function() { 
 
      \t $('.product-more-pictures .down').removeClass('disabled') 
 
      \t if(thumb_active.prevAll(':lt(1)').length) { 
 
       thumb_active.prevAll(':lt(1)').children().click() 
 
       thumb_active = jQuery('.gallery-container .active'); 
 
      } 
 
      
 
      \t if(! thumb_active.prev().length) { 
 
       $(this).addClass('disabled') 
 
      } else { 
 
       $(this).removeClass('disabled'); 
 
      } 
 
      
 
      if (click_count > 0) { 
 
       click_count = click_count - 1; 
 
       
 
       update_gallery('up'); 
 
       
 
      } 
 
     }); 
 
     
 
     function update_gallery(direction) {   
 
      gallery_offset = click_count * image_height; 
 
      last_images_count = thumb_active.nextAll().length; 
 
      
 
      $(".gallery-container").animate({ 
 
       'top': '-' + gallery_offset + 'px' 
 
      }, 800); 
 
     
 
     } 
 
     
 
});
.product-more-pictures a { 
 
    display: block; 
 
    text-align: center; 
 
} 
 

 
.product-more-pictures a.disabled { 
 
    pointer-events: none !important; 
 
    cursor: default; 
 
    visibility: visible !important; 
 
    background: #C3C3C3; 
 
} 
 

 
.product-more-pictures a.down.disabled:before, 
 
.product-more-pictures a.up.disabled:before{ 
 
\t content: ' '; 
 
    background: rgba(255, 255, 255, 0.42); 
 
    position: absolute; 
 
    height: 100%; 
 
    width: 100%; 
 
    left: 0px; 
 
    bottom: 0px; 
 
} 
 

 
.product-more-pictures { 
 
    text-align: right; 
 
    height: 549px; 
 
    width: 111px; 
 
    overflow: hidden; 
 
    position: relative; 
 

 
} 
 

 
.gallery-container { 
 
    position: relative; 
 
    padding: 30px 0px; 
 
} 
 

 
.gallery-container img { 
 
    margin-bottom: 0px; 
 
} 
 

 
#product-photos .product-more-pictures { 
 
    width: 18.516667%; 
 
} 
 

 
.product-more-pictures .up, 
 
.product-more-pictures .down { 
 
    position: absolute; 
 
    background: #999; 
 
    padding: 0px; 
 
    width: 100%; 
 
    text-align: center; 
 
    z-index: 80; 
 
    color: #fff; 
 
    padding: 5px 10px; 
 
} 
 

 
.product-more-pictures .up { top: 0px; } 
 
.product-more-pictures .down { 
 
    bottom: 0px; 
 
} 
 

 
.product-more-pictures a.active img { 
 
    border: solid 1px rgba(95, 95, 95,0.75) !important; 
 
} 
 

 
.product-more-pictures .icon-chevron-up, 
 
.product-more-pictures .icon-chevron-down { 
 
    color: #fff !important; 
 
    font-size: 21px; 
 
    position: relative; 
 
} 
 

 
.product-more-pictures .icon-chevron-up { 
 
    top: 0px; 
 
} 
 

 
.zoomContainer { z-index: 999; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="product-more-pictures desktop-3"> 
 
     <a href="#" class="up">up</a> 
 
     <div class="gallery-container"> 
 
     
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_027_compact.jpg?v=1451925772" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_111_compact.jpg?v=1451925773"alt="Sheer Perfection Tunic"> 
 
      </a> 
 
     
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_194_compact.jpg?v=1451925774" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#" > 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_029_compact.jpg?v=1451925774" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_095_compact.jpg?v=1451925775" data-image-id="8200864135" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_135_compact.jpg?v=1451925776" data-image-id="8200864327" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#" > 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_149_compact.jpg?v=1451925776" data-image-id="8200864775" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#" > 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_152_compact.jpg?v=1451925777" data-image-id="8200865671" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
    
 
      <a href="#"> 
 
      <img class="thumbnail" src="//cdn.shopify.com/s/files/1/0190/3782/products/Name_it_to_Win_It_11-27_159_compact.jpg?v=1451925778" data-image-id="8200866183" alt="Sheer Perfection Tunic"> 
 
      </a> 
 
     
 
     </div> 
 
     <a href="#" class="down">down</a> 
 
    </div>

+0

hat dies neu abgestimmt, da es das Snapping-Problem löst – Vincent

0

$(function(){ 
 
     var image_height = 0; 
 
     var gallery_offset = 0; 
 
     var image_count = $('img.thumbnail').length; 
 
     var image_show = 3; 
 
     var click_count = 0; 
 
     \t var image_height = 0; 
 
     var last_images_count = 0; 
 
     
 
     $('.gallery-container a').click(function(){ 
 
      $('.gallery-container a').removeClass('active') 
 
     \t $(this).addClass('active'); 
 
      
 
     }); 
 
     
 
     \t jQuery('.thumbnail').each(function(){ 
 
      $(this).on('load', function(){ image_height = $(this).parent().outerHeight(); }); 
 
      image_height = $(this).parent().outerHeight(); 
 
     }) 
 
     
 
     // Disable arrows if the images count is 3 below 
 
     if(image_count <= 3) { 
 
     \t $('.product-more-pictures .up, .product-more-pictures .down').addClass('disabled') 
 
      click_count = 0; 
 
     } 
 
     
 
     // Set the first image as active 
 
     jQuery('.gallery-container img.thumbnail').first().click(); 
 
     \t var thumb_active = jQuery('.gallery-container .active'); 
 
     
 
     $('.gallery-container a').on('click', function() { 
 
     \t thumb_active = jQuery('.gallery-container .active'); 
 
     }); 
 

 
     $('.product-more-pictures .down').on('click', function (e) { 
 
      \t $('.product-more-pictures .up').removeClass('disabled') 
 
      \t if(thumb_active.nextAll(':lt(1)').length) { 
 
       thumb_active.nextAll(':lt(1)').children().click() 
 
       thumb_active = jQuery('.gallery-container .active'); 
 

 
      } 
 
      
 
      if(! thumb_active.next().length || click_count > (image_count-image_show)) { 
 
       $(this).addClass('disabled') 
 
      } else { 
 
       $(this).removeClass('disabled'); 
 
      } 
 
      
 
      if (click_count < (image_count-image_show)) { 
 
       click_count = click_count+1; 
 
       update_gallery('down'); 
 
      } 
 
      
 
      
 
      \t 
 
     }); 
 

 
     $('.product-more-pictures .up').on('click', function() { 
 
      \t $('.product-more-pictures .down').removeClass('disabled') 
 
      \t if(thumb_active.prevAll(':lt(1)').length) { 
 
       thumb_active.prevAll(':lt(1)').children().click() 
 
       thumb_active = jQuery('.gallery-container .active'); 
 
      } 
 
      
 
      \t if(! thumb_active.prev().length) { 
 
       $(this).addClass('disabled') 
 
      } else { 
 
       $(this).removeClass('disabled'); 
 
      } 
 
      
 
      if (click_count > 0) { 
 
       click_count = click_count - 1; 
 
       
 
       update_gallery('up'); 
 
       
 
      } 
 
     }); 
 
     
 
     function update_gallery(direction) { 
 
      gallery_offset = click_count * image_height; 
 
      last_images_count = thumb_active.nextAll().length; 
 
      
 
      $(".gallery-container").animate({ 
 
       'top': '-' + gallery_offset + 'px' 
 
      }, 800); 
 
     
 
     } 
 
     
 
});

Hallo,

erforderliche Änderung

I hav e hinzugefügt eine weitere veriable image_show = 3 für Handle Bildanzahl.