How does Google achieve the fading effect on the home page?

后端 未结 7 2172
猫巷女王i
猫巷女王i 2021-01-14 06:27

If you go to google.com, you notice the menu on top slowly appears once you have mouse over the page. I was wondering what does Google use to control the fading effect?

相关标签:
7条回答
  • 2021-01-14 07:02

    I would think that they set the initial opacity of the elements other than the search box to zero. When the mouseover event is fired, the elements' opacity is gradually increased to 1.

    Edit: In code it would look something like this:

    var hiddenStuff = document.getElementByClassName("hiddenStuff");
    
    var interval=document.setInterval(function() {
        for (var i=0; i<hiddenStuff.length;i++){
            hiddenStuff[i].style.opacity+=0.1
        }
        if (hiddenStuff[1].style.opacity===1){
            window.clearInterval(interval);
        }
    }, 100);
    

    You may need to tweak the parameters to get a smooth animation.

    0 讨论(0)
提交回复
热议问题