브라우저 높이(Height) 값이 변경될때, 스크립트 실행시키기
마스터욱
0
33
0
0
2020-03-24 21:49:20
function onElementHeightChange(elm, callback){
var lastHeight = elm.clientHeight, newHeight;
(function run(){
newHeight = elm.clientHeight;
if( lastHeight != newHeight )
callback(newHeight)
lastHeight = newHeight
if( elm.onElementHeightChangeTimer )
clearTimeout(elm.onElementHeightChangeTimer)
elm.onElementHeightChangeTimer = setTimeout(run, 200)
})()
}
onElementHeightChange(document.body, function(h){
console.log('Body height changed:', h)
});
/////////////////////////////////////////////////////////
모바일에서 input 입력시 키패드가 생겼다가 없어졌다가 할때, div 높이값을 변경해야 하는 일이 생겼다.
그래서 구글링에서 검색후 스텍오버플로우에서 찾아낸 주옥같은 소스~