Skip to content

Instantly share code, notes, and snippets.

@naokisekiguchi
Created October 24, 2016 12:10
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/5e3257b0dc72c25ae0b7e7abe5373ad4 to your computer and use it in GitHub Desktop.
Save naokisekiguchi/5e3257b0dc72c25ae0b7e7abe5373ad4 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より小さいときは、minの値で固定する
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