Reputation: 11
Hay, (sorry for my english) i wrote this code
jQuery(function(){
$(function () {
$(window).scroll(function () { //Fonction appelée quand on descend la page
if ($(this).scrollTop() > 200 ) { // Quand on est à 200pixels du haut de page,
$('#scrollUp').css('right','10px'); // Replace à 10pixels de la droite l'image
} else {
$('#scrollUp').removeAttr( 'style' ); // Enlève les attributs CSS affectés par javascript
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="scrollUp">
<a href="#top"><img src="img/to_top.png"/></a>
</div>
its a button on my page to go to the Header, but i want the back to header going to slow. I'm novice in JS and Jquery, anyone can help me please?
Upvotes: 1
Views: 26
Reputation: 178375
You can add a behaviour
This does not need jQuery
Also your jQuery function was wrapped in a function, that is not needed
html {
scroll-behavior: smooth;
}
#top {
height: 2000px;
background-color: red
}
<div id="top">Top</div>
<div id="scrollUp">
<a href="#top"><img src="img/to_top.png" /></a>
</div>
Upvotes: 1