2012-04-09 4 views
1

그래서 레이아웃 섹션 (레이아웃 페이지의 div와 mvc3을 사용하는 div)을 숨기는 데 어려움을 겪고 있습니다.레이아웃 페이지에서 hidding 요소 mvc3

나는이 기본적으로 메인 로직 조각 JS 있습니다

$('.contentExpand').bind('click', function() { 
      $.cookie('right_container_visible', "false"); 
     }); 

     //Cookies Functions======================================================== 
     //Cookie for showing the right container 
     if ($.cookie('right_container_visible') === 'false') { 
      if ($('#RightContainer:visible')) { 
       $('#RightContainer').hide(); 
      } 
      $.cookie('right_container_visible', null); 
     } else { 
      if ($('#RightContainer:hidden')) { 
       $('#RightContainer').show(); 
      } 
     } 

당신이 볼 수 있듯이, 메신저 hidding 내가 특정 CSS를 몇 가지 링크에 클릭 할 때마다 용기. 이것은 간단한 테스트에서 잘 작동하는 것 같습니다. 하지만 테스트를 시작할 때

.contentExpand 클릭 -> 자세히 버튼 클릭 -> 내용 확장 클릭 -> [여기 예기치 않은 문제 : 줄 $ .cookie ('right_container_visible', null); 읽혀 지지만 vaule을 무시하는 것처럼 null로 설정하지 마십시오.]

임을 구현하려고하는데 올바른 논리를 이해하려합니다. 아무도 내가 이것을 해결할 수있는 방법을 알고 있니?

답변

0

나 요소의 크기 조정을 잡을 수있는 이벤트를 만드는 것이었다 근무 가장 좋은 것은. 나는 다른 지위에서 이것을 얻었다. 그러나 나는 어느 것을 기억하고 있지 않다. 여기에 이벤트 코드가 있습니다 :

//Event to catch rezising============================================================================ 
(function() { 
var interval; 
jQuery.event.special.contentchange = { 
    setup: function() { 
     var self = this, 
     $this = $(this), 
     $originalContent = $this.text(); 
     interval = setInterval(function() { 
      if ($originalContent != $this.text()) { 
       $originalContent = $this.text(); 
       jQuery.event.handle.call(self, { type: 'contentchange' }); 
      } 
     }, 100); 
    }, 
    teardown: function() { 
     clearInterval(interval); 
    } 
}; 
})(); 
//========================================================================================= 

//Function to resize the right container============================================================ 
(function ($) { 
$.fn.fixRightContainer = function() { 

    this.each(function() { 

     var width = $(this).width(); 
     var parentWidth = $(this).offsetParent().width(); 
     var percent = Math.round(100 * width/parentWidth); 
     if (percent > 62) { 
      $('#RightContainer').remove(); 
     } 
    }); 
}; 
})(jQuery); 
//=================================================================================================== 
0

가장 간단한 해결책은 바인드의 대리자 외부에서 변수를 만드는 것입니다. 예를 들어 :

var rightContVisibility = $.cookie('right_container_visible'); 
$('.contentExpand').bind('click', function() { 
      $.cookie('right_container_visible', "false"); 
      rightContVisibility = "false"; 
     }); 

if (rightContVisibility === 'false') { 
... 
} 
관련 문제