LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code



CSS
.controls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 200;
  height: 100%;
  text-align: center;
  pointer-events: none;
  visibility: hidden;
}

.control {
  position: absolute;
  top: 0;
  height: 100%;
  cursor: pointer;
  pointer-events: auto;
  visibility: visible;
}
.control:before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  top: 50%;
  font-family: 'FontAwesome';
  -webkit-transform: translate(0, -50%);
          transform: translate(0, -50%);
}

.prev {
  left: 0;
}
.prev:before {
  content: '\f104';
}

.next {
  right: 0;
}
.next:before {
  content: '\f105';
}

.pagination {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 200;
  text-align: center;
}
.pagination span {
  display: inline-block;
  cursor: pointer;
  border-radius: 100%;
}
.pagination span.active {
  pointer-events: none;
}

.baby {
  max-width: 100%;
  margin: 0 auto;
  padding-left: 0;
  list-style: none;
}

.baby-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  -webkit-transition: opacity 0.3s, visibility 0.3s, -webkit-transform 0.3s;
  transition: opacity 0.3s, visibility 0.3s, -webkit-transform 0.3s;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s, -webkit-transform 0.3s;
  -webkit-transform: translate(-100%, 0);
          transform: translate(-100%, 0);
}
.baby-item.active ~ * {
  -webkit-transform: translate(200%, 0);
          transform: translate(200%, 0);
}
.baby-item.active + * {
  -webkit-transform: translate(100%, 0);
          transform: translate(100%, 0);
}
.baby-item.active {
  position: relative;
  -webkit-transform: translate(0, 0);
          transform: translate(0, 0);
}

.control {
  width: 15%;
  font-size: 3.5em;
}

.pagination {
  text-align: center;
}
.pagination span {
  height: 1em;
  width: 1em;
  margin: 2% 1%;
  background: rgba(255, 255, 255, 0.5);
}
.pagination span:hover {
  background: rgba(255, 255, 255, 0.75);
}
.pagination span.active {
  background: rgba(0, 0, 0, 0.5);
}

*,
*:before,
*:after {
  box-sizing: border-box;
  position: relative;
}

*:before,
*:after {
  pointer-events: none;
}

html {
  overflow-x: hidden;
  font-family: 'Oswald';
}

.baby-item {
  height: 100vh;
}
.baby-item:before {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 16vmin;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
}
.baby-item:nth-child(1) {
  background: #16F4D0;
}
.baby-item:nth-child(1):before {
  content: "1";
}
.baby-item:nth-child(2) {
  background: #429EA6;
}
.baby-item:nth-child(2):before {
  content: "2";
}
.baby-item:nth-child(3) {
  background: #153B50;
}
.baby-item:nth-child(3):before {
  content: "3";
}
.baby-item:nth-child(4) {
  background: #f53B50;
}
.baby-item:nth-child(4):before {
  content: "4";
}
JS
// Link me to your sonicSlide in action!

// Version 28.0

// Shuffle elements on load
// https://css-tricks.com/snippets/jquery/shuffle-dom-elements/

// Automatic Rotation
// setInterval(function() {
//   $('.controls--modifier .next').trigger('click');
// }, 10000);


babySonicSlide(
  'baby',
  '.baby-controls', 
  '.baby-pagination', 
  '.baby-item');

function babySonicSlide(list, listController, listPagination, listElement) {
  
  // Variable Setup
  // =================
  
  var prev = listController + ' .prev';
  var next = listController + ' .next';
  
  var pagination = listPagination;
  	var paginationItem = pagination + ' span';
  
  var element = listElement;
  
  var activeClass = 'active';
    var activeElement = element + '.' + activeClass;
  
  
  // Setup Controls
  // =================
  
  $(listController)
    .append('')
    .append('');
  
  
  // Setup Pagination
  // =================
  
  if(!($(pagination + ' span').length)) {
    
    $(element).each(function() {

      $(pagination)
        .append('');

    });
    
  }
  
  
  // Preparations
  // =================
  
  $(element + ':first-child')
    .addClass(activeClass);
  
  $(paginationItem + ':first-child')
    .addClass(activeClass);
  
  
  // Actions
  // =================
  
  // Previous Click
  // =================
  
  $(prev).click(function() {
    
    if($(element + ':first-child').hasClass(activeClass)) {
      
      $(activeElement)
        .removeClass(activeClass);
      
      $(element)
        .last()
          .addClass(activeClass);
      
    }
    
    else {
      
      $(activeElement)
        .removeClass(activeClass)
        .prev()
          .addClass(activeClass);
    
    }
    
    coordinatePagination();
    
  });
  
  
  // Next Click
  // =================
  
  $(next).click(function() {
    
    if($(element + ':last-child').hasClass(activeClass)) {
      
      $(activeElement)
        .removeClass(activeClass);
      
      $(element)
        .first()
          .addClass(activeClass);
      
    }
    
    else {
      
      $(activeElement)
        .removeClass(activeClass)
        .next()
          .addClass(activeClass);
    
    }
    
    coordinatePagination();
    
  });
  
  
  // Pagination Click
  // =================
  
  $(paginationItem).click(function() {
    
    $(paginationItem)
      .removeClass(activeClass);
    $(this)
      .addClass(activeClass);
    
    $(activeElement)
      .removeClass(activeClass);
    $(element + ':nth-child(' + ($(paginationItem + '.' + activeClass).index() + 1) + ')')
      .addClass(activeClass);
    
  });
  
  
  // Pagination Coor.
  // =================
  
  function coordinatePagination() {
    
    $(paginationItem)
      .removeClass(activeClass);
    $(paginationItem + ':nth-child(' + ($(activeElement).index() + 1) + ')')
      .addClass(activeClass);
    
  }
  
  
  
  //stackoverflow.com/questions/2264072/detect-a-finger-swipe-through-javascript-on-the-iphone-and-android
  var listContainer =  document.getElementsByClassName(list);
  listContainer = listContainer[0];
  
  listContainer.addEventListener('touchstart', handleTouchStart, false);
  listContainer.addEventListener('touchmove', handleTouchMove, false);

  var xDown = null;
  var yDown = null;

  function handleTouchStart(evt) {
    xDown = evt.touches[0].clientX;
    yDown = evt.touches[0].clientY;
  };
  
  function handleTouchMove(evt) {
    if ( ! xDown || ! yDown ) {
      return;
    }

    var xUp = evt.touches[0].clientX;
    var yUp = evt.touches[0].clientY;

    var xDiff = xDown - xUp;
    var yDiff = yDown - yUp;

    if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {
      
      if ( xDiff > 0 ) {
        $('.next').trigger('click');
      } else {
        $('.prev').trigger('click');
      }
      
    }

    /* reset values */
    xDown = null;
    yDown = null;
  };

}

Description

Leave the slideshow to the css! Adding an active class based on user interaction with the controls
Term
Mon, 11/27/2017 - 21:30

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv