2017-05-07 56 views
1

我现在开始使用javascript和CSS,并且我被困在一个测试项目中。
我做了什么,我根据其他来源的搜索,所以我不知道是否有什么东西完全在正确的位置,可能不是。
所以,我试图根据窗口大小调整图像大小。
我做了它的头,但不能让它适用于我的导航栏背景。jQuery来rezise background-image

CSS:

.menutop { 
    background: url('Images/topo1.png') no-repeat top center; 
    height: 50px; 
    font-family: 'StreamArtsFont'; 
    text-align: center; 
    -webkit-animation: changeColor 30s infinite; 
} 

脚本:

jQuery(document).ready(function($){ 
    function fullscreen(){ 
    //Header size change 
     jQuery('#header').css({ 
      width: jQuery(window).width(), 
      height: jQuery(window).height() 
     }); 
    //Navbar size change 
     jQuery(".menutop").css("background-size", 'auto '+jQuery(window).height()+" cover"); 
    } 

Basicaly,我需要做的是改变背景-size元素的高度值,通过“jQuery的(提供的值窗口).height()“,就像我对标题做的一样。 我正在成像它的“自动”和jQuery(窗口).height()错误,因为当我只使用“封面”它的作品。 谢谢!

回答

1

background-size只需要2个值,而不是3个。而$(window).height()将返回一个整数。您需要将px附加到该字符串,以便它知道您尝试使用哪种单位。

我假设你想这样做,而不是。

jQuery(".menutop").css('background-size', 'auto '+jQuery(window).height() + 'px'); 
+1

它的工作!哈哈哈谢谢!这澄清了很多! –