Skip to content

Commit 5e22063

Browse files
committed
Fixed issue with multiple fadeIn() calls
1 parent f971124 commit 5e22063

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

ScrollTop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function run()
3535
Html::tag(
3636
'i',
3737
'',
38-
['class'=>'glyphicon glyphicon-menu-up scroll-top-circle']
38+
['class'=>'glyphicon glyphicon-menu-up bluezed-scroll-top-circle']
3939
),
4040
'#',
41-
['id'=>'btn-top-scroller', 'class'=>'scroll-top']
41+
['id'=>'btn-top-scroller', 'class'=>'bluezed-scroll-top']
4242
);
4343
}
4444
}

assets/css/scroll-top.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @license https://github.com/bluezed/yii2-scroll-top/blob/master/LICENSE
55
*/
66

7-
.scroll-top {
7+
.bluezed-scroll-top {
88
position: fixed;
99
bottom: 10px;
1010
right: 15px;
@@ -13,7 +13,7 @@
1313
text-align: center;
1414
}
1515

16-
.scroll-top-circle {
16+
.bluezed-scroll-top-circle {
1717
border-radius: 50%;
1818
width: 25px;
1919
height: 25px;
@@ -23,6 +23,6 @@
2323
color: #ffffff;
2424
}
2525

26-
.scroll-top-circle:hover {
26+
.bluezed-scroll-top-circle:hover {
2727
background-color: #666666;
2828
}

assets/js/scroll-top.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
$(function(){
88

9-
var btnScroller = $("#btn-top-scroller");
9+
var btnScroller = $('#btn-top-scroller');
10+
var scrollerTriggerPoint = $('html, body').offset().top + 150;
1011

11-
$(document).on("scroll", function() {
12-
var top = $("html, body").offset().top;
13-
if ($(window).scrollTop() > top+150) {
12+
$(document).on('scroll', function() {
13+
var pos = $(window).scrollTop();
14+
if (pos > scrollerTriggerPoint && !btnScroller.is(':visible')) {
1415
btnScroller.fadeIn();
15-
} else {
16+
} else if (pos < scrollerTriggerPoint && btnScroller.is(':visible')) {
1617
btnScroller.fadeOut();
1718
}
1819
});
1920

20-
btnScroller.on("click", function(e) {
21+
btnScroller.on('click', function(e) {
2122
e.preventDefault();
22-
$("html, body").animate({ scrollTop: 0 }, 300);
23+
$('html, body').animate({ scrollTop: 0 }, 300);
2324
});
2425

2526
});

0 commit comments

Comments
 (0)