-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollUp.js
78 lines (62 loc) · 1.87 KB
/
ScrollUp.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Project: scrollUP
* Description: a simple scrollUp item which can be used with every element.
* Author: BlackArray[] - Stefan Jud
* License: Apache v2
*/
;(function ($, window, document, undefined) {
var
pluginName = "scrollUP",
dataKey = "plugin_" + pluginName;
var Plugin = function (element, options) {
this.element = element;
this.$element = $(element);
this.options = {
RightPos: 10,
BottomPos: 10
};
this.init(options);
console.log("test");
};
Plugin.prototype = {
// initialize options
init: function (options) {
$.extend(this.options, options);
//Basic init of the scroll item
$(this.element).css( "position", "fixed" );
$(this.element).css("display", "none");
$(this.element).css( "right", this.options.RightPos );
$(this.element).css( "bottom", this.options.BottomPos );
}
};
$.fn[pluginName] = function (options) {
var plugin = this.data(dataKey);
var element = this;
var $item = $(element)
// has plugin instantiated ?
if (plugin instanceof Plugin) {
// if have options arguments, call plugin.init() again
if (typeof options !== 'undefined') {
plugin.init(options);
}
} else {
plugin = new Plugin(this, options);
this.data(dataKey, plugin);
}
//watch for click
this.bind("click.pluginName", function () {
$("html, body").animate({
scrollTop: 0
}, 600);
});
//watch for scrollposition
$(window).bind("scroll.pluginName", function (event) {
if ($(this).scrollTop() > 100) {
element.fadeIn();
} else {
element.fadeOut();
}
});
return plugin;
};
}(jQuery, window, document));