响应背景屏幕视图

响应背景屏幕视图

问题描述:

我想改变的背景时,我得到一个不同的屏幕大小,并将它没有重复和中心响应背景屏幕视图

$(function(){ 
    var moblie; 
    moblie = '<section id="mobile-bk-cg"></section>'; 

    if ($(window).width() <= 425){ 
     $({'.demo-heading-wrapper').css('background-image','url(../assets/images/mobile/mobile-425-image.jpg'), 
      'background-repeat': 'no-repeat', 'fixed'); 
    } else{ 
     $('.demo-heading-wrapper').css('background-image','url(../assets/images/mobile/mobile-demo-main-img-2.jpg'), 
      'background-repeat': 'no-repeat', 'fixed'); 
    } 
}); 

尝试做的是在CSS中,而不是用jQuery

你可以写里面@media为below.Change宽度和高度的方式根据自己的需要

@Media screen and (min-width: 320px) and (max-width: 480px){ 
    background : url(<URL here>); 
    background-repeat: no-repeat; 
    background-position: <Set percentage > 
} 

的代码块只是供大家参考。您的需求可能会有所不同,请根据您的需要更改宽度和参数。同样按照要求编辑CSS属性

+0

确定很酷,但是他们是否可以在我发布的代码中使用它? – cord

+0

请浏览有关媒体查询在以下链接 https://www.w3schools.com/css/css3_mediaqueries_ex.asp 兼谈中心使用CSS的图像,在这里找到它 HTTPS://www.w3。 org/Style/Examples/007/center.en.html –

+0

如果您发现答案正确,请将其标记为答案 –