Attention, c'est dépendant de jQuery, evidemment !
Permet d'afficher un élément pour remonter en haut d'une page, une fois qu'on a atteint un certain scroll de la page totale
$(document).on( 'scroll', function() { var dheight=$('body').height()-$(window).height(); if ($(this).scrollTop()>=dheight*.75 && !$('.ontop').hasClass("ontop_showed") && dheight>0) $('.ontop').addClass("ontop_showed"); else if ($(this).scrollTop()<dheight*.75 && $('.ontop').hasClass("ontop_showed")) $('.ontop').removeClass("ontop_showed"); });
Ici c'est à 75% du défilement total que l'élement .ontop acquiert la classe ontop_showed
Il suffit de décrire l'élement en HTML :
<div><a href="#" class="ontop">^</a></div>
On peut même rajouter de quoi faire un scroll smoothy
$('.ontop').click(function() { $('html, body').animate({scrollTop:0}, 'slow'); return false; });