I'm trying to scroll a div to the top while it is hidden. Here's my sample code:
function slideUpReset(div) {
$(div).slideUp('fast', function() {
$(div).scrollTop(0);
});
}
But this doesn't work. $(div).scrollTop(0)
only works when the div isn't hidden. Is there a way I can achieve the effect I want?
Try this :
if($('#div').prop('display')=='none')
{
$('#div').scroll();
$("#div").animate({ scrollTop: 1000 }, 2000);
}
All you have to do is wrap the hidden div in another div then scroll to that eg:
<div id=wrapperdiv> ** your hidden div ** </div>
then update your jquery to scroll to this div
function slideUpReset(div) {
$(div).slideUp('fast', function() {
$(div).parent().scrollTop(0);
});
}
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.