Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initSlider() {
- 'use strict';
- var slider = $('.slider'),
- slides = slider.find('.slider__slide'),
- slidesCount = slides.length,
- activeSlide = 0,
- sliderInterval,
- refreshButton = $('.slider__refresh'),
- sliderTitle = $('.slider__title'),
- SLIDER_TIMEOUT = 5000;
- slides.each(function() {
- var image = $(this).find('.slider__image');
- $(this).css('background-image', 'url(' + image.attr('src') + ')');
- image.remove();
- });
- if (slidesCount > 1)
- startSlider();
- function startSlider() {
- sliderInterval = setInterval(function() {
- changeSlide();
- }, SLIDER_TIMEOUT);
- }
- function changeSlide() {
- $(slides.get(activeSlide)).css('position', 'absolute').fadeOut(1000);
- activeSlide++;
- if (activeSlide >= slidesCount)
- activeSlide = 0;
- var slide = $(slides.get(activeSlide));
- slide.css('position', '').fadeIn(1000).css('display', 'table');
- sliderTitle.text(slide.data('title'));
- }
- refreshButton.click(function() {
- if (activeSlide !== 0) {
- clearInterval(sliderInterval);
- $(slides.get(activeSlide)).css('position', 'absolute').fadeOut(1000);
- activeSlide = 0;
- var slide = $(slides.get(activeSlide))
- slide.css('position', '').fadeIn(1000).css('display', 'table');
- sliderTitle.text(slide.data('title'));
- startSlider();
- }
- });
- }
- function bindVideo() {
- 'use strict';
- var videoPreview = $('.video__preview'),
- videoViewer = $('.video-viewer'),
- iframe = 'video-viewer__iframe';
- videoPreview.click(function() {
- var video = $(this).parent(),
- videoSource = video.data('video-src');
- if (!videoSource) return false;
- videoViewer.append("<iframe class='" + iframe + "' src=" + videoSource + " allowfullscreen></iframe>");
- videoViewer.fadeIn().css('display', 'flex');
- });
- videoViewer.click(function(e) {
- var target = $(e.target);
- if (!target.is('.' + iframe)) {
- $('.' + iframe).remove();
- $(this).fadeOut();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement