아이패드에서 스크롤을 기억할 필요가 있었다.
(페이지 이동시 전페이지의 스크롤을 기억할...)
document.body.scrollTop으로쿠키값을 대입하면
유독 아이패드에서는 제대로 될 때와 제대로 되지않은 경우가 발생하여,
타이머로 맞을때까지(오차1정도까지는 허용해주고 ) 재설정하도록 해보았다.
onload에서는 쿠키값을 읽어서 맞을때까지 화면을 재조정하고
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function onload(){
//plan6이라는 frame이 onload될때 스크립트를 실행.
var strCook = document.cookie;//저장된 쿠키 값을 받아온다.
if(strCook.indexOf("!~")!=0) {
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2, intE);//스크롤 위치를 구한다.
//document.body.scrollTop = strPos;//스크롤 위치를 적용시킨다.
if(strPos <= 0){
return;
}
var diff=strPos-window.pageYOffset;
if(diff > 30){
document.body.scrollTop = strPos;
TimeOutInterval = 10;
}else{
document.body.scrollTop = strPos;
TimeOutInterval = 5;
}
if(diff > 2){
setTimeout ("onload()", TimeOutInterval);
}
}
}
function onload(){
//plan6이라는 frame이 onload될때 스크립트를 실행.
var strCook = document.cookie;//저장된 쿠키 값을 받아온다.
if(strCook.indexOf("!~")!=0) {
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2, intE);//스크롤 위치를 구한다.
//document.body.scrollTop = strPos;//스크롤 위치를 적용시킨다.
if(strPos <= 0){
return;
}
var diff=strPos-window.pageYOffset;
if(diff > 30){
document.body.scrollTop = strPos;
TimeOutInterval = 10;
}else{
document.body.scrollTop = strPos;
TimeOutInterval = 5;
}
if(diff > 2){
setTimeout ("onload()", TimeOutInterval);
}
}
}
스크롤 위치 쿠키에 저장하는건 각 필요 이벤트에 넣어줬다
Body의 onscroll에 넣어도 되려나...
function SetDivPosition()
{
var abswindowbottom = 0;
if (typeof(window.pageYOffset) == 'number')
abswindowbottom = abswindowbottom + window.pageYOffset;
else if (document.body && document.body.scrollTop)
abswindowbottom = abswindowbottom + document.body.scrollTop;
else if (document.documentElement && document.documentElement.scrollTop)
abswindowbottom = abswindowbottom + document.documentElement.scrollTop;
alert(abswindowbottom);
var intY = abswindowbottom;
document.cookie = "yPos=!~"+intY+"~!";
}
</script>
</HEAD>
<BODY onload="onload()">
웹어딘가에서 얻은 어느 분들의 소스를 조금씩 합쳐서 우선 해결했다.{
var abswindowbottom = 0;
if (typeof(window.pageYOffset) == 'number')
abswindowbottom = abswindowbottom + window.pageYOffset;
else if (document.body && document.body.scrollTop)
abswindowbottom = abswindowbottom + document.body.scrollTop;
else if (document.documentElement && document.documentElement.scrollTop)
abswindowbottom = abswindowbottom + document.documentElement.scrollTop;
alert(abswindowbottom);
var intY = abswindowbottom;
document.cookie = "yPos=!~"+intY+"~!";
}
</script>
</HEAD>
<BODY onload="onload()">
급하게 하다보니 출처를 모르겠다...