我正在使用Unslider并且滑块工作得很好。
我在每个幻灯片中都有<li>
一个<h1>
标题。
我有一个 resizeH1()
调整这个大小的功能<h1>
:
function resizeH1() {
var $h1 = $('.entry-header h1');
if (window.innerWidth >= 768) {
// Calculate the total height of the element
var totalHeight = ($h1.height());
var numOfLines = totalHeight / 88;
// Force this element height to always be 88px
$h1.height(88);
// Adjust $h1 font-size depending on it's number of lines
if (numOfLines === 2) {
$h1.css('font-size', '42px');
} else if (numOfLines === 3) {
$h1.css('font-size', '40px');
} else if (numOfLines === 4) {
$h1.css('font-size', '38px');
} else if (numOfLines >= 5) {
$h1.css('font-size', '28px');
}
// Align the $h1 text verticaly at the very end
if (numOfLines >= 2) {
$h1.css({
'text-align': 'center',
'display': 'flex',
'justify-content': 'center',
'align-items': 'flex-end'
});
}
} else {
// Reset the $h1 state when (window.innerWidth < 768)
$h1.css({
'height': '',
'font-size': '',
'text-align': '',
'display': '',
'justify-content': '',
'align-items': ''
});
}
}
我的问题是这个功能只适用于第一个<h1>
,<li>
其他
的<h1>
都<li>
和font-size
第一个一样!
如何resizeH1()
在每个<li>
而不是第一个上运行?
在发布之前,我已经尝试了我所知道的所有内容并进行了很多搜索。
非常感谢您的任何建议/帮助。