作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
专家您好
这是我的 HTML:
<div class="full-height">
<h1>Lorem</h1>
</div>
我正在使用 jQuery 设置 div.full-height
的高度,如下所示:
$(document).ready(function() {
function setHeight() {
viewportHeight = $(window).height();
$('.full-height').height(viewportHeight);
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
现在我尝试使用 jQuery UI 将 div.full-height
中的 h1
的位置设置为 center center
如下:
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
问题是,如果我在 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);
$('.full-height > h1').position({
my: 'center center',
at: 'center center',
of: '.full-height'
});
};
setHeight();
$(window).resize(function() {
setHeight();
});
});
谢谢!
问候
拉尔夫
关于javascript - jQuery UI .position() 错过了使用 jQuery .height() 设置的目标元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758501/
我无法在附加行中显示“真”、“假”、"is"和“否”按钮。 我在这里有一个应用程序:Application 请按照以下步骤使用应用程序: 1。当你打开应用程序时,你会看到一个绿色的加号按钮,点击 在此
我是一名优秀的程序员,十分优秀!