summaryrefslogtreecommitdiff
path: root/public/vendor/showup/showup.js
blob: da987858f4ccaf21d6631e096d519e6004749c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Showup.js jQuery Plugin
 * http://github.com/jonschlinkert/showup
 *
 * Copyright (c) 2013 Jon Schlinkert, contributors
 * Licensed under the MIT License (MIT).
 */


(function( $ ) {
  $.fn.showUp = function(ele, options) {
    options = options || {};

    var target         = $(ele);
    var down           = options.down        || 'navbar-hide';
    var up             = options.up          || 'navbar-show';
    var btnHideShow    = options.btnHideShow || '.btn-hide-show';
    var hideOffset     = options.offset      || 60;
    var previousScroll = 0;
	var isHide		   = false;

    $(window).scroll(function () {
		checkScrollTop();
    });
	
	$(window).resize(function () {
		checkScrollTop();
    });
	
	$(window).mousewheel(function () {
		checkScrollTop();
    });
	
	function checkScrollTop()
	{
		target.clearQueue();
		target.stop();
	  var currentScroll = $(this).scrollTop();
      if (currentScroll > hideOffset && !target.hasClass('locked')) {
          if(Math.abs(previousScroll - currentScroll) < 50) return;
        if (currentScroll > previousScroll) {
          // Action on scroll down
		  target.removeClass(up).addClass(down);
        } else if (currentScroll < previousScroll) {
          // Action on scroll up
		  target.removeClass(down).addClass(up);
        }
      } else {
		target.removeClass(down).addClass(up);
	  }
      previousScroll = $(this).scrollTop();
	}

    // Toggle visibility of target on click
    $(btnHideShow).click(function () {
      if (target.hasClass(down)) {
        target.removeClass(down).addClass(up);
      } else {
        target.removeClass(up).addClass(down);
      }
    });
  };
})( jQuery );

// TODO: make customizable
$(document).ready(function () {
  var duration      = 420;
  var showOffset    = 220;
  var btnFixed      = '.btn-fixed-bottom';
  var btnToTopClass = '.back-to-top';

  $(window).scroll(function () {
    if ($(this).scrollTop() > showOffset) {
      $(btnFixed).fadeIn(duration);
    } else {
      $(btnFixed).fadeOut(duration);
    }
  });

  $(btnToTopClass).click(function (event) {
    event.preventDefault();
    $('html, body').animate({
      scrollTop: 0
    }, duration);
    return false;
  });
});