Advertisement
Guest User

Untitled

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