Összevariáltam. Működőképesen:
back-to-top.js
Kód:
jQuery( document ).ready(function($){
var offset = 444,
speed = 999,
duration = 500,
scrollButton = $('#up');
$(window).scroll(function() {
var theta = $(window).scrollTop() / 99 % Math.PI;
$('#rightgear').css({ transform: 'rotate(-' + theta + 'rad)' });
});
$( window ).scroll( function() {
if ( $( this ).scrollTop() < offset) {
scrollButton.fadeOut( duration );
} else {
scrollButton.fadeIn( duration );
}
});
scrollButton.on( 'click', function(e){
e.preventDefault();
$( 'html, body' ).animate({
scrollTop: 0
}, speed);
});
});
functions.php
Kód:
function themeslug_add_button_script() {
wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/back-to-top.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'themeslug_add_button_script' );
function themeslug_add_scroll_button() {
echo '<a href="#" id="up"><img src="/img/top.png" id="rightgear"></a>';
}
add_action( 'wp_footer', 'themeslug_add_scroll_button' );
.css
Kód:
#up {
position: fixed;
right: 5px;
bottom: 40px;
display:none;
z-index:999;
}
demo: segits.be
Könyvjelzők