Advertisement
Boquete

Untitled

Jun 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     (function($) {
  2.         $.fn.timeline = function() {
  3.             var selectors = {
  4.                 id: $(this),
  5.                 item: $(this).find(".timeline-item"),
  6.                 activeClass: "timeline-item--active",
  7.                 img: ".timeline__img"
  8.             };
  9.             selectors.item.eq(0).addClass(selectors.activeClass);
  10.             selectors.id.css("background-image", "url(" + selectors.item.first().find(selectors.img).attr("src") + ")");
  11.  
  12.             var itemLength = selectors.item.length;
  13.             $('.content').scroll(function() {
  14.                 var max, min;
  15.                 var pos = ($('.experience').scrollTop()) + 100;
  16.                 selectors.item.each(function(i) {
  17.                     min = $(this).offset().top;
  18.                     max = ($(this).height() + $(this).offset().top);
  19.                     var that = $(this);
  20.                     if (i == itemLength - 2 && pos > min + $(this).height() / 2) {
  21.                         selectors.item.removeClass(selectors.activeClass);
  22.                         selectors.id.css("background-image", "url(" + selectors.item.last().find(selectors.img).attr('src') + ")");
  23.                         selectors.item.last().addClass(selectors.activeClass)
  24.                     } else if (pos <= max - 40 && pos >= min) {
  25.                         selectors.id.css("background-image", "url(" + $(this).find(selectors.img).attr('src') + ")");
  26.                         selectors.item.removeClass(selectors.activeClass);
  27.                         $(this).addClass(selectors.activeClass);
  28.                     }
  29.  
  30.                 });
  31.             });
  32.  
  33.         }
  34.     })(jQuery);
  35.     $("#timeline").timeline();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement