2011-02-08 5 views

답변

0

아래의 모든 변경 사항은 iframe에로드되는 페이지를 참조합니다.

먼저 div를 문서 본문의 맨 아래에 추가하십시오. 당신이 모달을 사용하고자 할 때

var body = $('body')[0]; 
$(body).append("<div id='modal' style='position:absolute;display:none;'></div>"); 

그런 다음, (함수 내에서) 다음 코드를 실행합니다 :

// to position it, do the following 
var body = $('body')[0]; 

// get the position and size info on the iframe 
var height = $(body).height(); 
var width = $(body).width(); 

// get the size information on the modal div 
var divHeight = $('#modal').height(); 
var divWidth = $('#modal').width(); 

// put it together to get the proper position 
var top = (height/2)-(divHeight/2); 
var left = (width/2)-(divWidth/2); 

// set it and we're done, hiya! 
$('#modal').css('top', top); 
$('#modal').css('left', left); 

// show the div 
$('#modal').css('display', 'block'); 

주 두 가지

  1. 당신은 모달 DIV를 추가해야 body 요소에 더 쉽게 생명을 불어 넣으십시오.
  2. 모달은 절대 위치를 가져야합니다 - 예를 들어 인라인으로 넣으십시오

가 부여하는 샷 :

+0

이봐 감사 답장을 많이. 문제는 내 자바 스크립트가 부모 문서에서 실행되고 있지 않다는 것입니다. 그것은 iframe의 문서 내부에서 실행 중입니다. 그래서 iframe의 오프셋을 찾는 방법이 필요합니다 (앞에서 언급했듯이) iframe 내부에있는 코드를 통해 찾으십시오. 고마워. – Mandai

+0

그런 다음 일반 페이지에서 모달을 가운데에 배치하는 것과 같습니다. 나는 회신을 갱신 할 것이다. – Shakakai

관련 문제