Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 背景图像缩放_Javascript_Html_Css - Fatal编程技术网

Javascript 背景图像缩放

Javascript 背景图像缩放,javascript,html,css,Javascript,Html,Css,我想在我正在重新整理的网站的各个部分添加背景图像 问题是,背景图像被放大了 见下文 仅仅创建一个新的css div是否更好更快。。有人能就语法提出建议吗 // Sections backgrounds var pageSection = $(".home-section, .page-section, .small-section, .split-section"); pageSection.each(function(indx){ if ($(this).attr("data-ba

我想在我正在重新整理的网站的各个部分添加背景图像

问题是,背景图像被放大了

见下文

仅仅创建一个新的css div是否更好更快。。有人能就语法提出建议吗

// Sections backgrounds

var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(indx){

    if ($(this).attr("data-background")){
        $(this).css("background-image", "url(" + $(this).data("background") + ")");
    }
});
css


应该是您的解决方案。

您可以稍微调整javascript以对部分进行分类

var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(){
    if ($(this).attr("data-background")){
        $(this).css("background-image", "url(" + $(this).data("background") + ")");
        $(this).addClass('full-background'); //adds the class
    }
});
然后使用CSS正确地设置样式

.full-background {
    background-size: cover;
 }
然而,这是CSS3风格,所以要小心IE8

var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(){
    if ($(this).attr("data-background")){
        $(this).css("background-image", "url(" + $(this).data("background") + ")");
        $(this).addClass('full-background'); //adds the class
    }
});
.full-background {
    background-size: cover;
 }