/includes/jquery.ui.totop.js

https://github.com/benjamindbloom/RRPortfolioSite · JavaScript · 58 lines · 46 code · 6 blank · 6 comment · 3 complexity · 1daf8822c62b730a6dc80f027ff8faf0 MD5 · raw file

  1. /*
  2. |--------------------------------------------------------------------------
  3. | UItoTop jQuery Plugin 1.1
  4. | http://www.mattvarone.com/web-design/uitotop-jquery-plugin/
  5. |--------------------------------------------------------------------------
  6. */
  7. (function($){
  8. $.fn.UItoTop = function(options) {
  9. var defaults = {
  10. text: 'To Top',
  11. min: 200,
  12. inDelay:600,
  13. outDelay:400,
  14. containerID: 'toTop',
  15. containerHoverID: 'toTopHover',
  16. scrollSpeed: 1200,
  17. easingType: 'linear'
  18. };
  19. var settings = $.extend(defaults, options);
  20. var containerIDhash = '#' + settings.containerID;
  21. var containerHoverIDHash = '#'+settings.containerHoverID;
  22. $('body').append('<a href="#" id="'+settings.containerID+'">'+settings.text+'</a>');
  23. $(containerIDhash).hide().click(function(){
  24. $('html, body').animate({scrollTop:0}, settings.scrollSpeed, settings.easingType);
  25. $('#'+settings.containerHoverID, this).stop().animate({'opacity': 0 }, settings.inDelay, settings.easingType);
  26. return false;
  27. })
  28. .prepend('<span id="'+settings.containerHoverID+'"></span>')
  29. .hover(function() {
  30. $(containerHoverIDHash, this).stop().animate({
  31. 'opacity': 1
  32. }, 600, 'linear');
  33. }, function() {
  34. $(containerHoverIDHash, this).stop().animate({
  35. 'opacity': 0
  36. }, 700, 'linear');
  37. });
  38. $(window).scroll(function() {
  39. var sd = $(window).scrollTop();
  40. if(typeof document.body.style.maxHeight === "undefined") {
  41. $(containerIDhash).css({
  42. 'position': 'absolute',
  43. 'top': $(window).scrollTop() + $(window).height() - 50
  44. });
  45. }
  46. if ( sd > settings.min )
  47. $(containerIDhash).fadeIn(settings.inDelay);
  48. else
  49. $(containerIDhash).fadeOut(settings.Outdelay);
  50. });
  51. };
  52. })(jQuery);