Created
October 24, 2016 12:10
-
-
Save naokisekiguchi/5e3257b0dc72c25ae0b7e7abe5373ad4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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