Slight background zoom on DOM load?

可紊 提交于 2020-01-06 13:08:39

问题


How to reproduce the effect on this website :

https://shop.stripe.com/

I mean waiting for the DOM to fully load before showing anything, and then having the background image zooming out for 1s. Pretty cool.


回答1:


It's done using different transition and transforms together. Demo: http://jsfiddle.net/lotusgodkk/eHAuh/2/

Key is to add/remove classes in 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);
}



回答2:


You can also do it easily with pure 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



来源:https://stackoverflow.com/questions/23844649/slight-background-zoom-on-dom-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!