2014-08-30 9 views
0

div의 높이를 기억할 수 있습니까? 예를 들어 하나의 웹 사이트에서 일부 콘텐츠가있는 div를 확장하고 콘텐츠가 다른 동일한 페이지 (동일한 ID 및 클래스)를 클릭합니다. 불행히도 모든 것이 새로 고침되고 div의 높이가 손실됩니다.jQuery 및 페이지 사이의 매개 변수 저장

나는 html로 된 프레임으로 효과를 얻었지만 (내가 어떻게 보이는지는 알 수 없다.) 어때? 세션에서 데이터를 유지 하시겠습니까? 누군가가

+1

[웹 저장소] (http://dev.w3.org/html5/webstorage/)를보십시오. http://www.html5rocks.com/en/features/storage ♦ https://developer.mozilla.org/en/docs/Web/Guide/API/DOM/Storage –

답변

1

당신은 단순히 HTML5 로컬 스토리지 메커니즘을 사용하여 요청하는 경우 내가 jQuery를, 스프링 MVC를 사용하고

... 예를 들어이 필요합니다.

.height(), .innerHeight() 또는 outerHeight()은 필요한 것을 기반으로 사용할 수 있습니다. 여기

enter image description here

는 예입니다 - jsfiddle.net/xK0nB1n

JQuery와

if(localStorage.divheight) //extract the old height 
{ 
    // handle the height as you want here 
    alert('Old height from local storage: '+ localStorage.divheight); 
} 

//Code just to show the mechanism of LocalStorage 
$(document).ready(function(){  
    $('#result').click (function() { 

     //Remember the height 
     localStorage.divheight = $("div").height(); 

     //Tell the user the freshly stored height 
     alert("New height: "+localStorage.divheight); 
    }); 
}); 

HTML

<div id="result"> 
    Some number of lines here.... 
    Lorem ipsum dolor sit amet, consectetur adipisicing elit 
    . Fuga earum id fugit veritatis! Pariatur, magni. 
</div>