element.scrollTop = 0;
will let you get to the element's scroll top:
var el = document.querySelector('div'); el.scrollTop = el.scrollHeight; setTimeout(function(){ el.scrollTop = 0; }, 500);
div{width:200px; height:200px; overflow:auto;}
<div> <br>Top-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>-<br>- </div>
请尝试以下方法:
window.scrollTo(0,0);
Give an id to your div. And then:
var myDiv = document.getElementById('yourdivid');
myDiv.scrollTop = 0;
If you need to animate, then try the below
$('html, body').animate({scrollTop: '0px'}, 2000);
If its a div you want to animate,
$('#yourid').animate({scrollTop: '0px'}, 1000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.