so I have this javascript:
$(window).scroll(function () {
if ($(window).scrollTop() > 0 && !document.contains(document.getElementById('toTop'))) {
var top = '<div id="toTop" onclick="tTop()"></div>';
$('body').append(top);
}
});
function tTop() {
$('html,body').scrollTop(0);
}
$(window).scroll(function () {
if (document.contains(document.getElementById('toTop')) && $(window).scrollTop() == 0) {
$('div').remove('#toTop');
}
});
It works just fine if the page is loaded while the scroll bar is at the top; however when I refresh the page while the scroll bar is at the bottom, the page will still scroll up, but the scroll stays at the bottom. Can anyone tell me how to fix this?
top
will be appended to your page...