(function($) { "use strict"; // 1.Hide Loading Box (Preloader) function handlePreloader() { if($('.preloader').length){ $('.preloader').delay(200).fadeOut(500); } } // 2.Update header style + Scroll to Top function headerStyle() { if($('.main-header-block').length){ var windowpos = $(window).scrollTop(); if (windowpos >= 150) { $('.main-header-block').addClass('fixed-header'); $('.scroll-to-top').fadeIn(300); } else { $('.main-header-block').removeClass('fixed-header'); $('.scroll-to-top').fadeOut(300); } } } headerStyle(); /* ========================When document is Scrollig, do===================== */ $(window).scroll('scroll', function() { // add your functions (function ($) { headerStyle(); })(jQuery); }); /* ========================When document is loaded, do===================== */ $(window).on('load', function() { // add your functions (function ($) { handlePreloader(); })(jQuery); }); })(window.jQuery); $(function(){ $(".scroll-to-top").on("click",function(){ $("html,body").animate({scrollTop:"0px"},1000) }) })