(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 $("body").append("

" + settings.scroll_to_top.label + "

"); // Preview function $("input").change(function () { // building the style for preview var style="" // building the html content of preview var html="

"; // if label enabled display it if($("#edit-scroll-to-top-display-text").attr('checked')){ html+=$("#edit-scroll-to-top-label").val(); } 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').show(); } else { $('#back-top').hide(); } }); // scroll body to 0px on click $('#back-top a').click(function () { $('body,html').animate({ scrollTop: 0 }, 800); return false; }); }); } }; })(jQuery);