var $positionAbsolute = $('#absolute').addClass('hide'); var $item = $('.hide-button').data('counter', 1); var $changeBgPreviosly = $('#change-bg-previous'); var $changeBgNext = $('#change-bg-next'); var arr = [ { 'background': 'url(img/combo.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, { 'background': 'url(img/combo1.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, { 'background': 'url(img/combo2.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, { 'background': 'url(img/combo3.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, { 'background': 'url(img/combo4.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, { 'background': 'url(img/combo.jpg)', 'background-color': 'rgba(0,0,0,0.3)', 'background-blend-mode': 'multiply', 'background-position': 'center', 'background-repeat': 'no-repeat' }, ]; var $background = $('#bg').css(arr[0]); var carousel = setInterval(function() { $background.css(arr[ Math.floor((Math.random() * 5) + 1) ]); }, 8000); $item.on('click', function(event) { event.preventDefault(); var counter = $item.data('counter'); $item.data('counter', counter + 1); if (counter !== 0) { $positionAbsolute.removeClass('hide').addClass('show').text(counter); } }); $changeBgPreviosly.on('click', function(){ event.preventDefault(); $background.css(arr[ Math.floor((Math.random() * 5) + 1) ]); }); $changeBgNext.on('click', function(){ event.preventDefault(); $background.css(arr[ Math.floor((Math.random() * 5) + 1) ]); }); $(window).scroll(function(){ if ($(this).scrollTop() > 200) { $('.scrollup').fadeIn(); } else { $('.scrollup').fadeOut(); } }); $('.scrollup').click(function(){ $("html, body").animate({ scrollTop: 0 }, 600); });