Skip to content

Commit

Permalink
Fixed issue with multiple fadeIn() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bluezed committed Jul 28, 2015
1 parent f971124 commit 5e22063
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ScrollTop.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function run()
Html::tag(
'i',
'',
['class'=>'glyphicon glyphicon-menu-up scroll-top-circle']
['class'=>'glyphicon glyphicon-menu-up bluezed-scroll-top-circle']
),
'#',
['id'=>'btn-top-scroller', 'class'=>'scroll-top']
['id'=>'btn-top-scroller', 'class'=>'bluezed-scroll-top']
);
}
}
6 changes: 3 additions & 3 deletions assets/css/scroll-top.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license https://github.com/bluezed/yii2-scroll-top/blob/master/LICENSE
*/

.scroll-top {
.bluezed-scroll-top {
position: fixed;
bottom: 10px;
right: 15px;
Expand All @@ -13,7 +13,7 @@
text-align: center;
}

.scroll-top-circle {
.bluezed-scroll-top-circle {
border-radius: 50%;
width: 25px;
height: 25px;
Expand All @@ -23,6 +23,6 @@
color: #ffffff;
}

.scroll-top-circle:hover {
.bluezed-scroll-top-circle:hover {
background-color: #666666;
}
15 changes: 8 additions & 7 deletions assets/js/scroll-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

$(function(){

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

$(document).on("scroll", function() {
var top = $("html, body").offset().top;
if ($(window).scrollTop() > top+150) {
$(document).on('scroll', function() {
var pos = $(window).scrollTop();
if (pos > scrollerTriggerPoint && !btnScroller.is(':visible')) {
btnScroller.fadeIn();
} else {
} else if (pos < scrollerTriggerPoint && btnScroller.is(':visible')) {
btnScroller.fadeOut();
}
});

btnScroller.on("click", function(e) {
btnScroller.on('click', function(e) {
e.preventDefault();
$("html, body").animate({ scrollTop: 0 }, 300);
$('html, body').animate({ scrollTop: 0 }, 300);
});

});

0 comments on commit 5e22063

Please sign in to comment.