PluginProbe ʕ •ᴥ•ʔ
WPFront Scroll Top / 1.5
WPFront Scroll Top v1.5
1.5 1.6 1.6.1 1.6.2 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.2 3.0.0 3.0.1 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5
wpfront-scroll-top / js / wpfront-scroll-top.js
wpfront-scroll-top / js Last commit date
options.js 9 years ago wpfront-scroll-top.js 9 years ago wpfront-scroll-top.min.js 9 years ago
wpfront-scroll-top.js
112 lines
1 /*
2 WPFront Scroll Top Plugin
3 Copyright (C) 2013, WPFront.com
4 Website: wpfront.com
5 Contact: syam@wpfront.com
6
7 WPFront Scroll Top Plugin is distributed under the GNU General Public License, Version 3,
8 June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
9 St, Fifth Floor, Boston, MA 02110, USA
10
11 */
12
13 (function () {
14 window.wpfront_scroll_top = function (data) {
15 var $ = jQuery;
16
17 var container = $("#wpfront-scroll-top-container").css("opacity", 0);
18
19 var css = {};
20 switch (data.location) {
21 case 1:
22 css["right"] = data.marginX + "px";
23 css["bottom"] = data.marginY + "px";
24 break;
25 case 2:
26 css["left"] = data.marginX + "px";
27 css["bottom"] = data.marginY + "px";
28 break;
29 case 3:
30 css["right"] = data.marginX + "px";
31 css["top"] = data.marginY + "px";
32 break;
33 case 4:
34 css["left"] = data.marginX + "px";
35 css["top"] = data.marginY + "px";
36 break;
37 }
38 container.css(css);
39
40 if (data.button_width == 0)
41 data.button_width = "auto";
42 else
43 data.button_width += "px";
44 if (data.button_height == 0)
45 data.button_height = "auto";
46 else
47 data.button_height += "px";
48 container.children("img").css({"width": data.button_width, "height": data.button_height});
49
50 if (data.hide_iframe) {
51 if ($(window).attr("self") !== $(window).attr("top"))
52 return;
53 }
54
55 var mouse_over = false;
56 var hideEventID = 0;
57
58 var fnHide = function () {
59 clearTimeout(hideEventID);
60 if (container.is(":visible")) {
61 container.stop().fadeTo(data.button_fade_duration, 0, function () {
62 container.hide();
63 mouse_over = false;
64 });
65 }
66 };
67
68 var fnHideEvent = function () {
69 clearTimeout(hideEventID);
70 hideEventID = setTimeout(function () {
71 fnHide();
72 }, data.auto_hide_after * 1000);
73 };
74
75 var scrollHandled = false;
76 var fnScroll = function () {
77 if (scrollHandled)
78 return;
79
80 scrollHandled = true;
81
82 if ($(window).scrollTop() > data.scroll_offset) {
83 container.stop().css("opacity", mouse_over ? 1 : data.button_opacity).show();
84 if (!mouse_over && data.auto_hide) {
85 fnHideEvent();
86 }
87 } else {
88 fnHide();
89 }
90
91 scrollHandled = false;
92 };
93
94 $(window).scroll(fnScroll);
95 $(document).scroll(fnScroll);
96
97 container
98 .hover(function () {
99 clearTimeout(hideEventID);
100 mouse_over = true;
101 $(this).css("opacity", 1);
102 }, function () {
103 $(this).css("opacity", data.button_opacity);
104 mouse_over = false;
105 fnHideEvent();
106 })
107 .click(function () {
108 $("html, body").animate({scrollTop: 0}, data.scroll_duration);
109 return false;
110 });
111 };
112 })();