Created
August 21, 2015 10:01
-
-
Save thierrypigot/46a1f71af58c2c83a9a7 to your computer and use it in GitHub Desktop.
Add back to top in Genesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ## Back to top | |
--------------------------------------------- */ | |
.eemi-top:hover { | |
color: #fff !important; | |
background-color: rgba(0,0,0,0.8); | |
text-decoration: none; | |
} | |
.eemi-top { | |
display: none; | |
position: fixed; | |
bottom: 1rem; | |
right: 1rem; | |
width: 3.2rem; | |
height: 3.2rem; | |
line-height: 3.2rem; | |
font-size: 1.4rem; | |
color: #fff; | |
background-color: rgba(0,0,0,0.3); | |
text-decoration: none; | |
border-radius: 3.2rem; | |
text-align: center; | |
cursor: pointer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function ($) { | |
// Back to top | |
var offset = 220; | |
var duration = 500; | |
$(window).scroll(function() { | |
if ($(this).scrollTop() > offset) { | |
$('.eemi-top').fadeIn(duration); | |
} else { | |
$('.eemi-top').fadeOut(duration); | |
} | |
}); | |
$('.eemi-top').click(function(event) { | |
event.preventDefault(); | |
$('html, body').animate({scrollTop: 0}, duration); | |
return false; | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Back to top | |
*/ | |
add_action( 'genesis_before', 'eemi_backToTop'); | |
function eemi_backToTop() | |
{ | |
if( !is_front_page() ) | |
echo '<a href="#" class="eemi-top">↑</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment