$(document).ready(function () { // Smooth scrolling $('a[href*="#"]') // Remove links that don't actually link to anything .not('[href="#"]') .not('[href="#0"]') .click(function (event) { // On-page links if ( location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname ) { // Figure out element to scroll to var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); // Does a scroll target exist? if (target.length) { // Only prevent default if animation is actually gonna happen event.preventDefault(); $('html, body').animate({ scrollTop: (target.offset().top - 148) }, 1000); } } }); if ($('body').hasClass('offer-body')) { // Get description column var desc = $('.description-col'); desc.on('click', function (e) { var target = $(e.target); if (target.hasClass('read-more')) { e.preventDefault(); var more = target.parent().next('.more'); target.fadeOut('fast', function () { more.toggle("slide"); }); } }); } $(window).on("load", function () { if ($('body').hasClass('page-start')) { var vid = $("#video"); var play = $("#play"); var pause = $("#pause"); var counterScreen = $("#counter"); //Seekbar updater var updatebar = function (x) { var progress = $('.progress'); //calculate drag position //and update video currenttime //as well as progress bar var maxduration = vid[0].duration; var position = x - progress.offset().left; var percentage = 100 * position / progress.width(); if (percentage > 100) { percentage = 100; } if (percentage < 0) { percentage = 0; } $('.timeBar').css('width', percentage + '%'); vid[0].currentTime = maxduration * percentage / 100; }; //Time format converter - 00:00 var timeFormat = function (seconds) { var m = Math.floor(seconds / 60) < 10 ? "0" + Math.floor(seconds / 60) : Math.floor(seconds / 60); var s = Math.floor(seconds - (m * 60)) < 10 ? "0" + Math.floor(seconds - (m * 60)) : Math.floor(seconds - (m * 60)); return m + ":" + s; }; counterScreen.text(timeFormat(vid[0].currentTime)); vid[0].play(); play.on("click", function () { if (vid.get(0).paused) { play.addClass('active'); pause.removeClass('active'); vid.get(0).play(); } }); pause.on("click", function () { if (!vid.get(0).paused) { pause.addClass('active'); play.removeClass('active'); vid.get(0).pause(); } }); //VIDEO PROGRESS BAR //when video timebar clicked var timeDrag = false; /* check for drag event */ $('.progress').on('mousedown', function (e) { timeDrag = true; updatebar(e.pageX); }); $(document).on('mouseup', function (e) { if (timeDrag) { timeDrag = false; updatebar(e.pageX); } }); $(document).on('mousemove', function (e) { if (timeDrag) { updatebar(e.pageX); } }); //display current video play time vid.on('timeupdate', function () { var currentPos = vid[0].currentTime; var maxduration = vid[0].duration; var perc = 100 * currentPos / maxduration; var curMins = Math.floor(vid.currentTime / 60); var curSecs = Math.floor(vid.currentTime - curMins * 60); if (curSecs < 10) { curSecs = "0" + curSecs; } $('.timeBar').css('width', perc + '%'); counterScreen.text(timeFormat(currentPos)); }); } }); var href = window.location.href; if ( href.indexOf('oferta') > -1 ) { $('body').addClass('offer-body'); $('.offer-s1:last').addClass('add-margin'); } $('.button.read-more').click(function(e) { e.preventDefault(); var btn = $(this); var more = $(this).parent().next('.more'); more.fadeOut('fast', function() { btn.toggle('slide'); more.show(500); }); }); });