简体   繁体   中英

How to Slide an Element In and Out of a Div

I'm trying to get better at JS and CSS, so I'm making a fake iPhone and am trying the simulate the look of when a text bubble pops on and off screen. This is what it looks like so far, and this is the HTML for the phone itself:

<div id="iPhone">
  <div id="screen"></div>
  <div id="me" class="bubble"></div>
   <div id="homeButton" class="circle"></div>
</div>

As well as the style sheet:

#iPhone {
  position: fixed;
  width: 250px;
  height: 500px;
  background-color: black;
  border-radius: 25px;
  top: 50%;
  right: 30%;
  transform: translate(-50%, -50%);
  -webkit-filter: blur(3px);
  box-shadow: 0 0 40px 20px white; 
  border: solid 2px white;
}

#me  {
background-color: #1D62F0;
margin-top: 130%;
margin-left: 25%;


}

#me::after{
  content: "";
  position: absolute;
  right: 0em;
  bottom: 0;
  width: 0.5em;
  height: 1em;
  border-left: 0.5em solid #1D62F0;
  border-bottom-left-radius: 1em 0.5em;
}

#screen {
position: fixed;
   width: 241px;
   height: 370px;
   background-color: white;
   border-radius: 0px;
   top: 8%;
   left: 1%;
   -webkit-filter: blur(3px);
   border: solid 2px black;

}

Right now, there's no JS governing it. How do I make it naturally slide onto the "screen" div and then disappear off the top, just like a real text message?

Thanks!

您需要将overflow: hidden属性放在消息容器div上,然后将新的消息框推入已存在的消息框下方,以便它们最终消失。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM