(function($){ /** * Toggle the visibility of the scroll to top link. */ Drupal.behaviors.scroll_to_top = { attach: function (context, settings) { // append back to top link top body if it is not var exist= jQuery('#back-top').length; // exist = 0 if element doesn't exist if(exist == 0){ // this test is for fixing the ajax bug $("body").append("
"); } // Preview function $("input").change(function () { // building the style for preview var style="" // building the html content of preview var html=""; // update the preview $("#scroll-to-top-prev-container").html(style+html); }); $("#back-top").hide(); $(function () { $(window).scroll(function () { if ($(this).scrollTop() > 100) { $('#back-top').fadeIn(); } else { $('#back-top').fadeOut(); } }); // scroll body to 0px on click $('#back-top a').click(function () { $('body,html').animate({ scrollTop: 0 }, 800); return false; }); }); } }; })(jQuery);