Commit: f57ce47b09e816f1f848f10b9eb5d5c6813ef871 Author: Dejan Marjanovic <[email protected]> Sun, 15 Dec 2013 18:48:29 +0100 Parents: 81fce1dcc4301b3ee2b7eeca74e762cbc8ad281d Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=f57ce47b09e816f1f848f10b9eb5d5c6813ef871 Log: Refactor 'to top' functions (E_TOO_MUCH_JQUERY) Changed paths: M include/footer.inc M js/common.js Diff: diff --git a/include/footer.inc b/include/footer.inc index 9de510b..078a695 100644 --- a/include/footer.inc +++ b/include/footer.inc @@ -71,6 +71,8 @@ UserVoice.push(['showTab', 'classic_widget', { }]); </script> +<a id="toTop" href="javascript:;"><span id="toTopHover"></span><img width="40" height="40" alt="To Top" src="/images/[email protected]"></a> + </body> </html> diff --git a/js/common.js b/js/common.js index bd8b296..8ad3548 100755 --- a/js/common.js +++ b/js/common.js @@ -165,50 +165,40 @@ $(document).ready(function() { /*{{{ Scroll to top */ (function() { - var settings = { - text: 'To Top', - min: 200, - inDelay:600, - outDelay:400, - containerID: 'toTop', - containerHoverID: 'toTopHover', - scrollSpeed: 400, - easingType: 'linear' - }; - var containerIDhash = '#' + settings.containerID; - var containerHoverIDHash = '#'+settings.containerHoverID; - - $('body').append('<a href="#" id="'+settings.containerID+'" onclick="return false;"><img src="/images/[email protected]" width="40" height="40" alt="'+settings.text+'"/></a>'); - $(containerIDhash).hide().click(function(){ - $('html, body').animate({scrollTop:0}, settings.scrollSpeed, settings.easingType); - $('#'+settings.containerHoverID, this).stop().animate({'opacity': 0 }, settings.inDelay, settings.easingType); - return false; - }) - .prepend('<span id="'+settings.containerHoverID+'"></span>') - .hover(function() { - $(containerHoverIDHash, this).stop().animate({ - 'opacity': 1 - }, 600, 'linear'); - }, function() { - $(containerHoverIDHash, this).stop().animate({ - 'opacity': 0 - }, 700, 'linear'); - }); - $(window).scroll(function() { - var sd = $(window).scrollTop(); - if (typeof document.body.style.maxHeight === "undefined") { - $(containerIDhash).css({ - 'position': 'absolute', - 'top': $(window).scrollTop() + $(window).height() - 50 - }); - } - if ( sd > settings.min ) { - $(containerIDhash).fadeIn(settings.inDelay); - } else { - $(containerIDhash).fadeOut(settings.outDelay); - } - }); + var settings = { + text: 'To Top', + min: 200, + inDelay: 600, + outDelay: 400, + containerID: 'toTop', + containerHoverID: 'toTopHover', + scrollSpeed: 400, + easingType: 'linear' + }; + + var toTopHidden = true; + var toTop = $('#' + settings.containerID); + + toTop.click(function(e) { + e.preventDefault(); + $.scrollTo(0, settings.scrollSpeed, {easing: settings.easingType}); + }); + + var toTopHidden = true; + $(window).scroll(function() { + var sd = $(this).scrollTop(); + if (sd > settings.min && toTopHidden) + { + toTop.fadeIn(settings.inDelay); + toTopHidden = false; + } + else if(sd <= settings.min && ! toTopHidden) + { + toTop.fadeOut(settings.outDelay); + toTopHidden = true; + } + }); })(); /*}}}*/ -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
