JS使用不同的填充
JS uses to different paddings
我的网站有问题。div class="行幻灯片内容"的填充顶部表现得很奇怪。对于某些幻灯片,它约为 223px,而对于其他幻灯片,它使用不同的填充。
.PHP
<div class="home-slider">
<ul class="slides">
<?php while ($slide =& $loop->next()): ?>
<li>
<div class="row slide-content">
<div class="large-10 large-centered columns text-center">
<?php if ( ! empty( $slide->button ) ) : ?>
<div class="SLIDERLOGO"><?php echo $slide->button; ?> </div>
<?php endif; ?>
<?php if ( ! empty( $slide->ititle ) || ! empty( $slide->caption ) ) : ?>
<div class="hero-title">
<div class="large-3 columns nopad border-bottom"></div>
<div class="large-6 columns text-center">
<?php if ( ! empty( $slide->ititle ) ) : ?>
<h4 class="text-white alt-h"><?php echo $slide->ititle; ?></h4>
<?php endif; ?>
</div>
<?php if ( empty( $slide->ititle ) ) : ?>
<div class="large-6 columns nopad border-bottom"></div>
<?php endif; ?>
<div class="large-3 columns nopad border-bottom"></div>
<h1 class="text-white"><?php echo $slide->caption; ?></h1>
</div><!--end of hero title-->
<?php endif; ?>
</div>
</div>
<img class="slider-bg" alt="<?php echo esc_attr( $slide->alt ); ?>" src="<?php echo esc_attr( $slide->img ); ?>" />
</li>
<?php endwhile; ?>
</ul>
</div><!--end of Home slider-->
徽标插入此处
<?php echo $slide->button; ?>
两个徽标的尺寸完全相同
.JS将 HTML 作为幻灯片的 CSS 背景追加 同时将幻灯片的内容居中
jQuery('.home-slider .slides li').each(function () {
var imgSrc = jQuery(this).children('.slider-bg').attr('src');
jQuery(this).css('background', 'url("' + imgSrc + '")');
jQuery(this).children('.slider-bg').remove();
var slideHeight = jQuery(this).height();
var contentHeight = jQuery(this).children('.slide-content').height();
var padTop = (slideHeight / 2) - (contentHeight / 2);
jQuery(this).children('.slide-content').css('padding-top', padTop);
});
这是指向我网站的链接http://timberlife.nl
它不会每次都发生,但有时徽标和页面顶部之间的填充会发生变化。我希望我已经解释了足够:)
非常感谢!大安
我已经在调试器上运行代码,并且可以将填充到 -8px。我认为这是因为jQuery document.ready函数不等待图像下载,因此您的li元素没有您期望的高度。
您能否将 jQuery 函数包装在以下代码中,以查看等到图像加载后是否可以解决问题?
$(window).bind("load", function() {
}
相关文章:
- spine.js在启动时填充模型实例
- Fabric.js-更改矩形填充
- 在EXT窗体面板中填充EXT JS存储
- 使用kendo js填充网格
- 如何在js中实现树结构类型的表单动态填充
- 如何在d3.js中填充svg圆圈内的图像
- 在Angular JS中,预先填充ng中的下拉值repeat
- 在Sails.js中通过关系填充多对多
- 在Angular JS中填充对象以进行插入
- 在 Node.js 中填充来自猫鼬的对象
- JS使用不同的填充
- 意思是.JS中间件中的猫鼬填充不起作用
- 设置图像以使用纸张.js填充画布
- 面积图的条件填充 D3.js
- 如何以类似于vivus.js的样式设置SVG填充和路径的动画
- 在刀片模板中填充js数组
- 用PHP填充JS代码段
- PHP:使用opendir填充JS幻灯片
- 在特定索引中填充JS数组
- 如何在我的谷歌浏览器扩展程序中将信息从后台传递.js到自动填充.js