Javascript jQuery UI.position()未命中使用jQuery.height()设置的目标元素的高度
各位专家您好 这是我的HTML:Javascript jQuery UI.position()未命中使用jQuery.height()设置的目标元素的高度,javascript,jquery,html,css,jquery-ui,Javascript,Jquery,Html,Css,Jquery Ui,各位专家您好 这是我的HTML: <div class="full-height"> <h1>Lorem</h1> </div> 现在,我尝试使用jQuery UI将div.full-height中h1的位置设置为center,如下所示: $(document).ready(function() { function setHeight() { viewportHeight = $(window).height()
<div class="full-height">
<h1>Lorem</h1>
</div>
现在,我尝试使用jQuery UI将div.full-height
中h1
的位置设置为center
,如下所示:
$(document).ready(function() {
function setHeight() {
viewportHeight = $(window).height();
$('.full-height').height(viewportHeight);
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
$(document).ready(function() {
function setHeight() {
viewportHeight = $(window).height();
$('.full-height').height(viewportHeight);
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
问题是,只有在CSS中设置了一个固定的height
属性,它才能正确定位
否则,div.full-height
具有全高,但其内部的h2
会粘在顶部,因为jQuery UI的.position()
函数不知道div.full-height
具有100%的高度
我怎样才能让它工作
问候
拉尔夫你好,专家们 那太快了。:-) 我刚刚解决了这个问题,将jQuery UI函数包含在调整大小的函数中,如下所示:
$(document).ready(function() {
function setHeight() {
viewportHeight = $(window).height();
$('.full-height').height(viewportHeight);
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
$(document).ready(function() {
function setHeight() {
viewportHeight = $(window).height();
$('.full-height').height(viewportHeight);
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
谢谢
问候
拉尔夫