Skip to content

Instantly share code, notes, and snippets.

@naokisekiguchi
Created October 24, 2016 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naokisekiguchi/334ace2c307642791c828a0621bbad0b to your computer and use it in GitHub Desktop.
Save naokisekiguchi/334ace2c307642791c828a0621bbad0b to your computer and use it in GitHub Desktop.
画面のスクロール処理
function scroll(val,min,max){
//ドキュメントの高さを取得
var ch = document.body.scrollHeight;
//距離センサの値がmaxより大きい時、何もしない
if(val > max){
return;
}
//距離センサがminより小さいときは、minValの値で固定する
if(val < min){
val = min;
}
//スクロールする位置を決定する
var sx = ch * (1 - (val - min)/(max - min));
//指定の位置にスクロールさせる
window.scrollTo(0,sx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment