わかりました私はこのコードを持っています:
//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var a = $(this).attr('vd');
var b = $(this).attr('id');
$.post('chk.php', { name : a, name2 : b }, function(output) {
$('#con').html(output).show();
});
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer
return false;
});
//Close Popups and Fade Layer
$('a.close').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block, .login').fadeOut(function() {
$('#fade').remove();
}); //fade them both out
return false;
});
//end poup
今、ユーザーがpoplightのクラスを持つ要素をクリックするたびに、上記のコードが実行され、popup_blockのクラスを持つdivを表示する必要がありますが、その前にajax関数が呼び出され、問題はありませんが、そのdiv(popup_blockのクラスを持つ)の中心主義が失われるか、そのdivの中心主義を実装するコードがそこにあることがわかりますが、そうではなく、位置を指定したときにのみ中心に置かれていることがわかりますcss または css 上のその div の幅と高さですが、私はそれをしたくありません。jquery 関数がそれを行う必要があります (コードを参照してください。そこに実装されています)。私のコードに不足があるか、何かが欠けているだけかもしれませんが、それが何であれ、私にはわかりません。助けてください、私は電話の際にそのdivを中央に配置したいだけです。よろしくお願いします。
-その div (popup_block のクラスを持つ) は固定配置され、z-index:99999 であり、デフォルトでは何も表示されません。