CSS transition fade in

前端 未结 4 1918
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 02:36

So I have used CSS transitions before but I have a unique case with this one. I am writing a custom plugin for creating modals. Essentially I create a div on the fly

4条回答
  •  既然无缘
    2020-12-03 03:14

    OK, first of all I'm not sure how it works when you create a div using (document.createElement('div')), so I might be wrong now, but wouldn't it be possible to use the :target pseudo class selector for this?

    If you look at the code below, you can se I've used a link to target the div, but in your case it might be possible to target #new from the script instead and that way make the div fade in without user interaction, or am I thinking wrong?

    Here's the code for my example:

    HTML

    Click 
    
    Fade in ...

    CSS

    #new {
        width: 100px;
        height: 100px;
        border: 1px solid #000000;
        opacity: 0;    
    }
    
    
    #new:target {
        -webkit-transition: opacity 2.0s ease-in;
           -moz-transition: opacity 2.0s ease-in;
             -o-transition: opacity 2.0s ease-in;
                                      opacity: 1;
    }
    

    ... and here's a jsFiddle

提交回复
热议问题