Skip to content

Instantly share code, notes, and snippets.

@yaroslavKas
Last active June 1, 2016 09:17
Show Gist options
  • Save yaroslavKas/ddc600811add1d9fd6626fc7096d5a77 to your computer and use it in GitHub Desktop.
Save yaroslavKas/ddc600811add1d9fd6626fc7096d5a77 to your computer and use it in GitHub Desktop.
Кнопки вверх/низ
.wrap-bottom {
position: fixed;
right: 15px;
bottom: 25px;
}
#ToTop,
#OnBottom {
width: 36px;
}
.go-up {
position: relative;
z-index: 9999;
cursor: pointer;
font-size: 40px;
opacity: .6;
display: block;
}
.go-up .fa-chevron-circle-up {
color: #AD9B74;
}
.go-down .fa-chevron-circle-down {
color: #AD9B74;
}
.go-down {
bottom: 10px;
}
.go-down:hover,
.go-up:hover {
opacity: 1;
}
<div class="wrap-bottom">
<div class="go-up" title="Top" id="ToTop" style="left: 0px;"><i class="fa fa-chevron-circle-up"></i></div>
<div class="go-down" title="Bottom" id="OnBottom" style="left: 100px;"><i class="fa fa-chevron-circle-down"></i></div>
</div>
jQuery(function(){
var trigerTop = 'show';
var trigerBottom = 'show';
var noSckroll = false;
hideButtonTop();
function hideButtonTop(){
if(trigerTop == 'show'){
jQuery("#ToTop").animate({ "left": "+=100px" }, "slow" );
trigerTop = 'hide';
}
}
function showButtonTop(){
if(trigerTop == 'hide'){
jQuery("#ToTop").animate({ "left": "-=100px" }, "slow" );
trigerTop = 'show';
}
}
function hideButtonBottom(){
if(trigerBottom == 'show'){
jQuery("#OnBottom").animate({ "left": "+=100px" }, "slow" );
trigerBottom = 'hide';
}
}
function showButtonBottom(){
if(trigerBottom == 'hide'){
jQuery("#OnBottom").animate({ "left": "-=100px" }, "slow" );
trigerBottom = 'show';
}
}
jQuery(window).scroll(function(){
if (jQuery(window).scrollTop()<="250") {
if(!noSckroll)
hideButtonTop();
}else {
if(!noSckroll)
showButtonTop();
}
});
jQuery(window).scroll(function(){
if (jQuery(window).scrollTop()>=jQuery(document).height()-"999"){
if(!noSckroll)
hideButtonBottom();
}
else {
if(!noSckroll)
showButtonBottom();
}
});
jQuery("#ToTop").click(function(){
noSckroll = true;
jQuery("html,body").animate({scrollTop:0},"slow",function(){noSckroll = false;})
hideButtonTop();
showButtonBottom();
});
jQuery("#OnBottom").click(function(){
noSckroll = true;
jQuery("html,body").animate({scrollTop:jQuery(document).height()},"slow",function(){noSckroll = false;})
showButtonTop();
hideButtonBottom();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment