Advertisement
Dimalolzet

drugoi-mir updates

May 16th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function initSlider() {
  2.     'use strict';
  3.  
  4.     var slider = $('.slider'),
  5.         slides = slider.find('.slider__slide'),
  6.         slidesCount = slides.length,
  7.         activeSlide = 0,
  8.         sliderInterval,
  9.         refreshButton = $('.slider__refresh'),
  10.         sliderTitle = $('.slider__title'),
  11.         SLIDER_TIMEOUT = 5000;
  12.  
  13.     slides.each(function() {
  14.         var image = $(this).find('.slider__image');
  15.         $(this).css('background-image', 'url(' + image.attr('src') + ')');
  16.         image.remove();
  17.     });
  18.  
  19.     if (slidesCount > 1)
  20.         startSlider();
  21.  
  22.     function startSlider() {
  23.         sliderInterval = setInterval(function() {
  24.             changeSlide();
  25.         }, SLIDER_TIMEOUT);
  26.     }
  27.  
  28.     function changeSlide() {
  29.         $(slides.get(activeSlide)).css('position', 'absolute').fadeOut(1000);
  30.  
  31.         activeSlide++;
  32.         if (activeSlide >= slidesCount)
  33.             activeSlide = 0;
  34.  
  35.         var slide = $(slides.get(activeSlide));
  36.         slide.css('position', '').fadeIn(1000).css('display', 'table');
  37.         sliderTitle.text(slide.data('title'));
  38.     }
  39.  
  40.     refreshButton.click(function() {
  41.         if (activeSlide !== 0) {
  42.             clearInterval(sliderInterval);
  43.             $(slides.get(activeSlide)).css('position', 'absolute').fadeOut(1000);
  44.             activeSlide = 0;
  45.             var slide = $(slides.get(activeSlide))
  46.             slide.css('position', '').fadeIn(1000).css('display', 'table');
  47.             sliderTitle.text(slide.data('title'));
  48.             startSlider();
  49.         }
  50.     });
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. function bindVideo() {
  62.     'use strict';
  63.  
  64.     var videoPreview = $('.video__preview'),
  65.         videoViewer = $('.video-viewer'),
  66.         iframe = 'video-viewer__iframe';
  67.  
  68.     videoPreview.click(function() {
  69.         var video = $(this).parent(),
  70.             videoSource = video.data('video-src');
  71.         if (!videoSource) return false;
  72.  
  73.         videoViewer.append("<iframe class='" + iframe + "' src=" + videoSource + " allowfullscreen></iframe>");
  74.         videoViewer.fadeIn().css('display', 'flex');
  75.     });
  76.  
  77.     videoViewer.click(function(e) {
  78.         var target = $(e.target);
  79.  
  80.         if (!target.is('.' + iframe)) {
  81.             $('.' + iframe).remove();
  82.             $(this).fadeOut();
  83.         }
  84.     });
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement