2013-10-11 40 views
0

我试图在Royalslider插件上绘制一个徽标。它设置为100%宽度和灵活宽度以适应响应式布局。我使用css在Royalslider顶部放置了一个徽标。它的工作原理,但不完全如何我喜欢它。我基本上计算滑块的当前高度,并将CSS margin-top设置为该值除以1.5。在Royalslider上分层显示图像在垂直中心位置

无论浏览器窗口的大小如何,我都希望它能够垂直居中。这可能吗?我的数学需要调整吗?任何想法都表示赞赏。

相关网址:

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

不是使用CPU密集型jQuery调整大小,而是分别在p和img元素上使用媒体查询断点,绝对位置和固定位置。顶部:p元素上的50%和img set per breakpoint上的宽度。