我正在尝试在Royalslider插件上添加徽标。它设置为100%宽度和灵活的宽度,以适应响应式布局。我用css在Royalslider顶部放置了一个标志。它的工作原理但不完全是我喜欢它的方式。我基本上计算了滑块的当前高度,并将CSS margin-top设置为该值除以1.5。
无论浏览器窗口的大小如何,我都希望将它垂直居中。这可能吗?我的数学需要调整吗?任何想法都表示赞赏。
相关网址:
http://www.bigideaadv.com/big_idea_v2/
当前HTML:
<div id="new-royalslider-1" class="royalSlider new-royalslider-1 rsUni rs-default-template" style="width:100%; height:450px;">
<div class="rsContent">
<img class="rsImg" src="http://www.bigideaadv.com/big_idea_v2/wp-content/uploads/2013/10/top_slide11-1024x560.jpg" alt="Entemanns slide"/>
</div>
<div class="rsContent">
<img class="rsImg" src="http://www.bigideaadv.com/big_idea_v2/wp-content/uploads/2013/10/top_slide1-1024x560.jpg" alt="PGPF Slide"/>
</div>
<div class="rsContent">
<img class="rsImg" src="http://www.bigideaadv.com/big_idea_v2/wp-content/uploads/2013/10/top_slide3-1024x560.jpg" alt="American Arbitration Association slide"/>
</div>
<div class="rsContent">
<img class="rsImg" src="http://www.bigideaadv.com/big_idea_v2/wp-content/uploads/2013/10/top_slide4-1024x560.jpg" alt="GDLSK slide"/>
</div>
<div class="rsContent">
<img class="rsImg" src="http://www.bigideaadv.com/big_idea_v2/wp-content/uploads/2013/10/top_slide5-1024x560.jpg" alt="uShuttl slide"/>
</div>
</div>
<p id="floating-logo" class="align-center"><img src="wp-content/themes/skeleton/images/parallax_logo.png" /></p>
当前CSS(仅限p标签):
#floating-logo {
display: block;
position: absolute;
margin: 0 auto 0 auto;
width: 100%;
z-index: 3000;
}
#floating-logo img {
margin: 0 auto 0 auto;
}
使用Javascript:
jQuery(document).ready(function() {
offsetHeight = jQuery("#new-royalslider-1").height();
offsetHeight = 0 - offsetHeight / 1.5;
//console.log(offsetHeight);
jQuery("p#floating-logo").css("margin-top", offsetHeight);
//console.log(jQuery("p#floating-logo").css("margin-top"));
$(window).resize(function() {
offsetHeight = jQuery("#new-royalslider-1").height();
offsetHeight = 0 - offsetHeight / 1.5;
console.log(offsetHeight);
jQuery("p#floating-logo").css("margin-top", offsetHeight);
console.log(jQuery("p#floating-logo").css("margin-top"));
})
});
答案 0 :(得分:0)
而不是使用CPU密集型jQuery大小调整,只是分别使用了媒体查询断点,p和img元素的绝对和固定位置。 top:每个断点的img设置p元素和宽度的50%。