Last active
August 29, 2015 14:07
-
-
Save kawabataryo/20419e556150f69261d5 to your computer and use it in GitHub Desktop.
指定したIDの縦の位置を配列で返す関数
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
/** | |
* @param {Array} idAry 位置を取得したい要素のID名を配列で ※必須 | |
* @param {Number} adjustPosition 位置を調整 [初期値=0] | |
* | |
* 取得したデータの呼び出し [インスタンス名].hashTalbe; | |
*/ | |
function GetElementsOffsetTop(idAry,adjustPosition){ | |
this.idAry = idAry; | |
this.len = this.idAry.length; | |
this.adjustPosition = adjustPosition || 0; | |
this.hashTable = this.generateObj(); | |
} | |
GetElementsOffsetTop.prototype = { | |
//連想配列を生成 | |
generateObj: function(){ | |
var hashObj = {}; | |
for(var i = 0; i < this.len; i++){ | |
hashObj[this.idAry[i]] = this.getPosition(i) + this.adjustPosition; | |
} | |
return hashObj; | |
}, | |
//要素の位置を取得 | |
getPosition: function(i){ | |
var el = document.getElementById(this.idAry[i]); | |
if(el){ | |
return el.offsetTop; | |
} | |
} | |
} |
Author
kawabataryo
commented
Oct 28, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment