-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotop.js
63 lines (54 loc) · 1.43 KB
/
totop.js
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
// ** ToTop Start **
(function($) {
// When to show the scroll link
// higher number = scroll link appears further down the page
var upperLimit = 1000;
// Our scroll link element
var scrollElem = $('#totop');
// Scroll to top speed
var scrollSpeed = 500;
// Show and hide the scroll to top link based on scroll position
$(window).scroll(function() {
var scrollTop = $(document).scrollTop();
if (scrollTop > upperLimit) {
$(scrollElem).stop().fadeTo(300, 1); // fade back in
} else {
$(scrollElem).stop().fadeTo(300, 0); // fade out
}
});
// Scroll to top animation on click
$(scrollElem).click(function() {
$('html, body').animate({
scrollTop: 0
}, scrollSpeed);
return false;
});
})(jQuery);
// ** TotopEnd**
// **SearchFrom**
var $searchWrap = $('#search-form-wrap'),
isSearchAnim = false,
searchAnimDuration = 200;
var startSearchAnim = function() {
isSearchAnim = true;
};
var stopSearchAnim = function(callback) {
setTimeout(function() {
isSearchAnim = false;
callback && callback();
}, searchAnimDuration);
};
$('#nav-search-btn').on('click', function() {
if (isSearchAnim) return;
startSearchAnim();
$searchWrap.addClass('on');
stopSearchAnim(function() {
$('.search-form-input').focus();
});
});
$('.search-form-input').on('blur', function() {
startSearchAnim();
$searchWrap.removeClass('on');
stopSearchAnim();
});
// SearchFrom End