PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/blackForest/js/jquery.scrollUp.js

https://gitlab.com/carolinasolfernandez/theme
JavaScript | 94 lines | 55 code | 15 blank | 24 comment | 6 complexity | c75141d23e07dd4f8fd6ed4d1943ac58 MD5 | raw file
  1. /*
  2. scrollUp v1.0.0
  3. Author: Mark Goodyear - http://www.markgoodyear.com
  4. Git: https://github.com/markgoodyear/scrollup
  5. Copyright 2013 Mark Goodyear
  6. Licensed under the MIT license
  7. http://www.opensource.org/licenses/mit-license.php
  8. Twitter: @markgdyr
  9. */
  10. ;(function ($) {
  11. $.scrollUp = function (options) {
  12. // Settings
  13. var settings = {
  14. scrollName: 'scrollUp', // Element ID
  15. topDistance: '300', // Distance from top before showing element (px)
  16. topSpeed: 300, // Speed back to top (ms)
  17. animation: 'fade', // Fade, slide, none
  18. animationInSpeed: 200, // Animation in speed (ms)
  19. animationOutSpeed: 200, // Animation out speed (ms)
  20. scrollText: 'Scroll to top', // Text for element
  21. activeOverlay: false // Set CSS color to display scrollUp active point, e.g '#00FFFF'
  22. };
  23. // Load settings
  24. if (options) {
  25. var settings = $.extend(settings, options);
  26. }
  27. // Shorthand setting names
  28. var sn = '#' + settings.scrollName,
  29. an = settings.animation,
  30. os = settings.animationOutSpeed,
  31. is = settings.animationInSpeed,
  32. td = settings.topDistance,
  33. st = settings.scrollText,
  34. ts = settings.topSpeed,
  35. ao = settings.activeOverlay;
  36. // Create element
  37. $('<a/>', {
  38. id: settings.scrollName,
  39. href: '#top',
  40. title: st,
  41. text: st
  42. }).appendTo('body');
  43. // Minium CSS to make the magic happen
  44. $(sn).css({
  45. 'display':'none',
  46. 'position': 'fixed',
  47. 'z-index': '2147483647'
  48. })
  49. // Active point overlay
  50. if (ao) {
  51. $("body").append("<div id='"+ settings.scrollName +"-active'></div>");
  52. $(sn+"-active").css({ 'position': 'absolute', 'top': td+'px', 'width': '100%', 'border-top': '1px dotted '+ao, 'z-index': '2147483647' })
  53. }
  54. // Scroll funtion
  55. $(window).scroll(function(){
  56. // Fade animation
  57. if (an === "fade") {
  58. $( ($(window).scrollTop() > td) ? $(sn).fadeIn(is) : $(sn).fadeOut(os) );
  59. }
  60. // SlideUp animation
  61. else if (an === "slide") {
  62. $( ($(window).scrollTop() > td) ? $(sn).slideDown(is) : $(sn).slideUp(os) );
  63. }
  64. // No animation
  65. else {
  66. $( ($(window).scrollTop() > td) ? $(sn).show(0) : $(sn).hide(0) );
  67. }
  68. });
  69. // Back to the top
  70. $(sn).click( function(event) {
  71. $('html, body').animate({scrollTop:0}, ts);
  72. return false;
  73. });
  74. }; // End scrollUp function
  75. }(jQuery));