ページの自動スクロール
1801 ワード
var timer = null;
var height = 0;
var width = 0;
var rewark = true;
var tag = true;
var tempTimer = null;
var search = undefined;
function startRun() {
if (timer != null) window.clearInterval(timer);
width = document.documentElement.scrollLeft;
height = document.documentElement.scrollTop;
tag = !tag;
timer = window.setInterval(function () {
scrollWindows();
}, 30);
}
function endRun() {
tag = !tag;
window.clearInterval(timer);
}
function scrollWindows() {
document.documentElement.scrollTo(width, height);
if (document.documentElement.scrollTop < height) {
rewark = !rewark;
//height = 0;
//window.scrollTo(0, 0);
}
if (!rewark) {
if (document.documentElement.scrollTop == 0) {
rewark = !rewark;
}
}
//
if (rewark) {
height += 1;
} else {
height -= 1;
}
}
window.onkeyup = function (e) {
if (e.keyCode == 13) {
if (!tag) startRun();
else endRun();
}
}
window.onmousemove = function () {
if (tag) endRun();
}
//window.onclick = function () {
// if (tag) endRun();
//}
window.onmousewheel = function () {
endRun();
}
}