2012-08-17 3 views
0

모달 창을 만드는 jQuery 플러그인을 개발 중이므로 이제 숨기고 나서 요소 원래 상태로 복원하려고합니다.jQuery 플러그인 개발 요소 원래 상태 보존

누군가 나를 도울 수 있습니까?

감사합니다.

---- 갱신 --- 죄송합니다

,

나는 그것을 보여 어떤 장소에서 요소의 HTML을 저장 한 후 다시 때 숨기기를 저장된 데이터를 배치합니다.

(function ($) { // v2ui_modal 
    var methods = { 
     show: function (options) { 
      var _this = this; 

      var defaults = { 
       showOverlay: true, 
       persistentContent: true 
      }; 

      var options = $.extend(defaults, options); 

      if (!_this.attr('id')) { 
       _this.attr('id', 'v2ui-id_' + Math.random().toString().replace('.', '')); 
      } 

      if (options.showOverlay) { 
       $('<div />', { // overlay 
        id: 'v2-ui-plugin-modal-overlay-' + this.attr('id'), 
        css: { 
         zIndex: ($.topZIndex() + 1), 
         display: 'none', 
         position: 'fixed', 
         width: '100%', 
         height: '100%', 
         top: 0, 
         left: 0 
        } 
       }).addClass('v2-ui').addClass('plugin').addClass('overlay').appendTo('body'); 
      }; 

      _this.css({ 
       zIndex: ($.topZIndex() + 2), 
       position: 'fixed' 
      }); 

      _this.center(); 

      $('#v2-ui-plugin-modal-overlay-' + _this.attr('id')).fadeIn(function() { 
       _this.fadeIn(); 
      }); 
     }, 

     hide: function() { 
      var _this = this; 

      _this.fadeOut(); 

      $('#v2-ui-plugin-modal-overlay-' + _this.attr('id')).fadeOut(function() { 
       $('#v2-ui-plugin-modal-overlay-' + _this.attr('id')).remove(); 
       if ((_this.attr('id')).substr(0, 8) == 'v2ui-id_') { 
        _this.removeAttr('id'); 
       }; 
      }); 
     } 
    }; 

    jQuery.fn.v2ui_modal = function (methodOrOptions) { 
     if (methods[methodOrOptions]) { 
      methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); 
     } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 
      methods.show.apply(this, arguments); 
     }; 
    }; 
})(jQuery); 
+1

너무 모호합니다. 몇 가지 코드를 게시하십시오. 너 뭐 해봤 니? – Utkanos

+0

우리가 지금까지 가지고있는 정보에서, 나는 다음과 같이 갈 것입니다 :'$ (". yourElement"). show();' –

+0

어떻게 정보를 얻을 수 있을까요? –

답변

1

당신은 jQuery.detach 좀 걸릴 수 있습니다 :

내 플러그인입니다.

.detach() 메소드는

() 제거 된 요소와 관련된 모든 데이터의 jQuery 유지 .detach 것을 제외 .remove()와 동일하다. 이 메서드는 제거 된 요소가 나중에 DOM에 다시 삽입 될 때 유용합니다.

그러나 문제를 완전히 이해하는 데 어려움을 겪고 있습니다. 그렇기 때문에 내 답변이 귀하의 질문에 맞지 않으면 사과드립니다.