1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| $( function(){
$('body').prepend('<a href="#top" class="top_link" title="Revenir en haut de page">Haut de page</a>');
$('.top_link').css({
'position' : 'fixed',
'width' : '70px',
'right' : '5px',
'bottom' : '5px',
'display' : 'none',
'padding' : '5px',
'background' : '#fff',
'background-color' : 'black',
'-moz-border-radius' : '30px',
'-webkit-border-radius' : '30px',
'border-radius' : '30px',
'z-index' : '2000',
'text-decoration' : 'none',
'color' : '#0090FF',
'font-family' : 'arial',
'font-size' : '14px',
'border' : '2px solid #0090FF',
'text-align' : 'center',
});
var jObjTop = $('.top_link'),
boolTop = true; // autoriser le fading
$( window ).scroll( function(){
var posScroll = $(document).scrollTop();
if ( boolTop && posScroll > 150 ){
jObjTop.fadeIn( 600 );
} else if ( boolTop && posScroll < 150 ){
jObjTop.fadeOut(600);
}
});
$('.top_link').click(function(){
boolTop = false; // interdire le fading
jObjTop.fadeOut(600); // mais cacher jObjTop
$('html,body').animate({scrollTop: 0}, 1000, function(){
boolTop = true; // autoriser le fading
});
});
}); |
Partager