Reputation: 41
I want to create a chat window which should animate open on click like following:
The chat window should be absolute to the viewport so I can move it in hindsight anywhere on the browser window. But I need to stick some elements like the input element and some icons inside the chat window to the bottom so I can animate the chat to open while these elements stay in place.
Would be nice if someone could help me out!
My html looks sort of this:
<div id="chat">
<svg id="openCloseWindow" height="28px" width="28px" viewbox="0 0 28 28"></svg>
<div id"IshouldStickToTheBottomOfTheChatWindow">
<svg id="chatEmote" height="28px" width="28px" viewbox="0 0 28 28"></svg>
<input id="messageBar" type="text" placeholder="message" name="message">
<div>
</div>
Upvotes: 3
Views: 56
Reputation: 167192
I believe it's really straightforward, using a position: fixed
and bottom: 0
. See the below snippet in its full screen:
.chat {
position: fixed;
bottom: 0;
right: 0;
width: 160px;
height: 20px;
background-color: #000;
border-radius: 15px 0 0 0;
transition: all 0.5s linear;
cursor: pointer;
color: #fff;
padding: 15px;
border: 2px solid #000;
}
.chat span {
color: #000;
background-color: #fff;
display: block;
padding: 3px;
border-radius: 3px;
border: 1px solid #000;
position: absolute;
bottom: 10px;
left: 10px;
right: 10px;
}
.chat.open {
height: 350px;
width: 250px;
color: #000;
background-color: #fff;
}
<div class="chat" onclick="this.classList.toggle('open');">
<span>Click Me!</span>
</div>
Preview
Upvotes: 2