潜水高度始终为零-如何使其自动假设高度
Div height always zero - how to make it assume height automatically
我想在我的网站上显示通知,AwNotices插件似乎是一个合适的解决方案。然而,问题是部分的高度始终为零,因此它不会向下推送任何内容,而是出现在同一部分上。
HTML:
<section class="awNotices">
<a notice-color="orange" href="http://adobewordpress.com" class=""><i class="fa fa-bell"></i>
<font><font> 'Tomorrowland' Is a Box-Office Disappointment</font></font></a>
<a notice-color="red" class="active"><i class="fa fa-heart"></i><font><font> Sunday Book Review: Shakespeare in Love</font></font></a>
<a notice-color="blue" class=""><i class="fa fa-desktop"></i><font><font> Overvalued in Silicon Valley, but Do not Say "Tech Bubble"</font></font></a>
<a notice-color="green" class=""><i class="fa fa-leaf"></i><font><font> Created for the World Health Emergency Fund Agency</font></font></a>
<a notice-color="dark" class=""><i class="fa fa-comments"></i><font><font> John Nash, Nobel Prize Winner, Dies in Crash.</font></font></a>
<span class="controller fa fa-pause"></span>
</section>
<div>
Hello World.
</div>
JS:
$('.awNotices').append('<span class="controller fa fa-pause"></span>');
$('.awNotices a:nth-of-type(1)').addClass('active');
function awNotice() {
if (!$('.awNotices').hasClass('stopped')) {
var $active = $('.awNotices a.active');
var $next = $active.next('a');
if ($next.length) {
$next.addClass('active');
$active.removeClass('active');
} else {
$active.removeClass('active');
$('.awNotices a:first-of-type').addClass('active');
}
}
}
$('.awNotices .controller').click(function () {
$(this).toggleClass('fa-pause fa-play');
$('.awNotices').toggleClass('stopped');
})
function awNotices(timer) {
setInterval("awNotice()", timer);
}
awNotices(2000);
我为它制作了一把小提琴:http://jsfiddle.net/pm3hz9x1/4/
我如何确保该部分自动占据其高度,并像它应该的那样向下推送所有内容?
我刚刚检查了你的小提琴,发现你的.awNotices a
有position:absolute;
,所以它不会在内容中发生实际位置(<section>
)。
如果我去掉它的位置,它是有效的,但它看起来很难看,因为您使用了visibility:hidden
。我去掉了可见性,用display none/block代替活动类。
现在它看起来很好,因为它应该是IMO。这是我用你的两个类修改的代码。
.awNotices a {
/* position: absolute; */
/* visibility: hidden; */
display: none;
}
.awNotices a.active {
/* visibility: visible; */
display: block;
}
上面的代码只显示更改后的特定CSS属性,您必须包含其他类属性才能获得预期的结果。请看一下我更新的小提琴!
相关文章:
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 如何重写下面的函数,使其不会't用于循环
- Ember选择绑定-如何使其着火
- 动态修改一个元素,使其与给定的选择器匹配
- 如何使用javascript操作SVG节点,使其在MS Edge中工作
- Javascript将数组转换为字符串并使其反向输出
- 如何添加两个变量而不使其在javascript中连接
- 在按钮改变高度后使标题保持不变
- 动态设置元素的高度以使其溢出:auto
- 如何在javascript中使其具有100%的宽度和高度
- 更改img高度,使其's具有一定的纵横比's宽度
- 如何使一个元素假位置:固定,使其行为固定,直到某个滚动高度,然后附加
- 潜水高度始终为零-如何使其自动假设高度
- 更改图像的源使其宽度/高度在第一次点击时为零
- 我如何使fancyBox 2调整其高度以适合其内容?
- 生成画布宽度和高度属性,使其大小与用户输入大小的矩形相同
- 如何拖动DIV,使其宽度和高度为负值
- 如何将文本偏移其高度的一半,使其垂直居中一个角度
- Javascript 用于 Div 高度,使其更快
- 使用Javascript扩展侧边栏高度,使其与内容高度相等