轻微的背景缩放DOM负载?

时间:2014-05-24 11:47:57

标签: javascript background zoom zooming

如何在本网站上重现效果:

https://shop.stripe.com/

我的意思是在显示任何内容之前等待DOM完全加载,然后让背景图像缩小1秒。很酷。

2 个答案:

答案 0 :(得分:1)

使用不同的过渡和变换完成。演示:http://jsfiddle.net/lotusgodkk/eHAuh/2/

关键是在document.ready

中添加/删除课程

HTML:

<div id="DIV_1" class="scaled"></div>

JS:

$(document).ready(function () {
    $('#DIV_1').attr('class', 'animatable');
    setTimeout(function () {
        $('#DIV_1').removeClass('animatable');
    }, 1000)
});

CSS:

#DIV_1 {
    background-position: 50% 50%;
    bottom: 0px;
    height: 472px;
    left: 0px;
    position: absolute;
    right: 0px;
    top: 0px;
    width: 600px;
    z-index: 1;
    background: rgba(0, 0, 0, 0) url(https://shop.stripe.com/assets/images/showcase/thairu-kat.jpg) no-repeat scroll 50% 50% / cover padding-box border-box;
    font: normal normal normal 16px/normal Helvetica, Arial, sans-serif;
    zoom:1.1;
    background-size:cover;
}
/*#DIV_1*/
 .animatable {
    -webkit-transition:all 750ms ease-out;
    transition:all 750ms ease-out;
}
.scaled {
    -webkit-transform:scale(1.02);
    transform:scale(1.02);
}

答案 1 :(得分:1)

您也可以使用纯javascript轻松完成:

的CSS:

#blackdiv { background: black; color: white; position: fixed; width: 100%; height: 100%; }

HTML:

<div id="blackdiv"></div>
<div>page content</div>

JS:

window.onload = function(){
    var blackdiv = document.getElementById('blackdiv');
    blackdiv.style.opacity = 1;
    doIt();
};

var doIt = function(){
    if( blackdiv.style.opacity > 0 ){
        console.log(blackdiv.style.opacity);
        blackdiv.style.opacity -= .1;
        setTimeout("doIt()", 100);
    }
}

<强> Check jsFiddle