아래의 코드 샘플을 사용하여 jQuery 쿠키 플러그인을 활용하여 각 div 요소의 토글 상태가 브라우저 세션을 초과하여 지속될 수 있습니다.쿠키로 div 토글 상태 유지하기
감사합니다.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};
$(document).ready(function(){
$('.toggle').show();
$('.hide').click(function(){
var t = $(this);
// toggle hidden div
t.parent().find('.toggle').slideFadeToggle(400, function(){
// determine which image to use if hidden div is hidden after the toggling is done
var imgsrc = ($(this).is(':hidden')) ? 'http://i47.tinypic.com/vg0hu0.gif' : 'http://i45.tinypic.com/281tsle.gif';
// update image src
t.attr('src', imgsrc);
});
})
})
</script>
</head>
<body>
<div class="wrapper">
<img class="hide" src="http://i45.tinypic.com/281tsle.gif" /> Header Text 1
<div class="toggle">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
<p>
<div class="wrapper">
<img class="hide" src="http://i45.tinypic.com/281tsle.gif" /> Header Text 2
<div class="toggle">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
</p>
</body>
</html>
답장을 보내 주셔서 감사 드리며 프로세스의 "흐름"을 알고 있습니다. 부족한 부분은 코드 예제가 어떻게 구현되었는지 보여줍니다. – Sandra
@Sandra : 저는 답을 추가 한 예제를 작성하고있었습니다. 기본 아이디어를 보여줍니다. –
죄송합니다. 마지막 질문이 하나 있습니다. div가 접힌 상태로 설정된 다음 페이지를 새로 고치면 토글 애니메이션이 실행되어 div가 확장 된 상태에서 접힌 상태로 바뀌 었음을 보여줍니다. 내가 잘못했거나 설계 상으로는 무엇입니까? – Sandra