Change divs as page scrolls - css

I'm trying to do something like this demo. As the page scrolls down, the various parts become visible. I added a jsfiddle here. As you can see, when the second line of text is hovered it overwrites the line above it. I know my code is using hover and the demo site changes with scrolling but I thought this would be easier to get to work first.
Would someone please explain how do I make it so only the contents of the div with ID changeme is enlarged without affecting the others? Here's my code:
<style>
#changeme {
height: 50px;
width:100px;
transition: all .5s ease-in-out;
}
#changeme:hover {
height: 200px;
width:100px;
transform: scale(1.5);
}
</style>
<div>
<h1>Title</h1>
<div>
<div>Main text<div>
<div id="changeme">
<div>Some Text</div>
<div><img src="example.png"></div>
</div>
</div>
</div>

Run this in full-page mode. Here you go:
var ScrollFunction = function() {
var y = window.scrollY;
var viewport = window.innerWidth;
var counter = (y/viewport) * 100;
if ( counter >= 10) {
document.getElementById("containerOne").className = "container show"
}
if (counter >= 20) {
document.getElementById("containerTwo").className = "container show"
}
if (counter >= 30) {
document.getElementById("containerThree").className = "container show"
}
};
window.addEventListener("scroll", ScrollFunction);
*{
margin: 0;
padding: 0;
box-sizing: border-box;
color: #fff;
}
body{
height: 200vh;
background-color: #313131;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.container{
width: 80%;
height: 500px;
border: 1px solid rgb(126, 126, 126);
margin-bottom: 5vh;
display: none;
justify-content: center;
align-items: center;
flex-direction: row;
}
.box{
width: calc(80%/4);
display: flex;
height: 50%;
opacity: 1;
margin-left: 10px;
justify-content: center;
align-items: center;
background-color: rgba(255, 255, 255, 0.185);
animation: 1s 1 linear normal showUp;
transition: .4s all;
}
.box:first-child{
margin: 0;
}
.box:hover{
transform: scale(1.5);
}
.show{
display:flex;
}
#keyframes showUp {
0%{
height: 0;
opacity: 0;
display: none;
}
100%{
display: flex;
height: 50%;
opacity: 1;
}
}
<div id="containerOne" class="container">
<div class="box">MyBox1</div>
<div class="box">MyBox2</div>
<div class="box">MyBox3</div>
<div class="box">MyBox4</div>
</div>
<div id="containerTwo" class="container">
<div class="box">MyBox1</div>
<div class="box">MyBox2</div>
<div class="box">MyBox3</div>
<div class="box">MyBox4</div>
</div>
<div id="containerThree" class="container">
<div class="box">MyBox1</div>
<div class="box">MyBox2</div>
<div class="box">MyBox3</div>
<div class="box">MyBox4</div>
</div>

If you want to change the size of an element on hover without affecting others then you can use just the transform: scale.
If you also (or instead of) alter the width and/or height then unless the element is positioned in some non-relative way it will 'disturb' elements around it.
So try:
#changeme:hover {
transform: scale(1.5);
}
When you come to want to expand elements as they come into view, investigate IntersectionObserver. You can attach an observer to each of those elements and as they appear you can transform them, or use CSS animate and/or a delay setting to get the sort of effects shown in the linked site.

Related

Set an image inside CSS spinner and want it to resize it.image should be in static

I am working on an angular application and implemented spinner using CSS.
Now the spinner working as expected.
I have added a background image inside the CSS using background-image:url()
Here, the problem is image also rotate with the spinner.
Here is my CSS
#spinner {
-webkit-animation: frames 1s infinite linear;
animation: frames 1s infinite linear;
background: transparent;
border: .3vw solid #FFF;
border-radius: 100%;
border-top-color: #250463;
background-image:url("../../../../assets/images/svg/img.svg") ;
width: 5vw;
height: 5vw;
opacity: .6;
padding: 0;
position: absolute;
z-index: 999;
justify-content: center;
align-items: center;
}
#keyframes frames {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
.spinner-wrapper {
position: fixed;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 998;
}
html code
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
</div>
Experiment 1
added another style img
img {
max-width: 5vw;
position: absolute;
max-height: 5vw;
top: 0;
height: 5vw;
width: 5vw;
clip-path: circle(45% at 50% 49%);
}
i have updated my html code as well
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="">
</div>
Experiment 2
added background-attachment: fixed; inside spinner.Still the image is rotating
**Experiment 3 **
I made below changes.now its working
added new css
z-index: 8;
justify-content: center;
top:230px;
left: 575px;
.img {
position: absolute;
top: 0;
width: 42px;
height: 48px;
}
html changes
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="../../../../assets/images/svg/img.svg">
</div>
One draw back is here.if i change the screen size,spinner and image appears different position
how can i solve this
Now the image showing some where else in the UI.
how can i include image inside the spinner.
How can i stop spinning my image?
Can we set image size
This is my first experience on CSS.If anything wrong please correct me.

how to make apply multiple elements on hover css

This is my first time posting sorry in advance, this is my first time trying to make a website for uni.
Im trying to make 2 things happen to my image on hover, I want it to:
blur
make text appear
Ive managed to make it blur but cant seem to make any text appear on top of the blur.
CSS:
'''.container {
display: flex;
flex-wrap: nowrap;
width: 100vw;
height: 100vh;
justify-content: space-evenly;
}
.fern {
max-width: 50vw;
max-height: 100vh;
}
img {
max-width:100%;
max-height: 80vh;
}
.venus {
max-width: 50vw;
}
.venus:hover {
-webkit-filter:blur(10px);
transition: .5s ease;
cursor: pointer;
}
.fern:hover {
-webkit-filter:blur(10px);
transition: .5s ease;
cursor: pointer;
}
'''
HTML:
<body>
<h1 class="guide">
a guide to wellness and growth
</h1>
<div class="container">
<div class="fern">
<img src="./assets/images/fern_nobg.png" alt="fern_nobg">
</div>
<div class="venus">
<img src="./assets/images/venus_nobg.png" alt="venus_nobg">
</div>
</div>
</div>
</body>
I have tried this
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_display_element_hover
and
https://www.youtube.com/watch?v=W0ubfqwd4G4
and neither of them worked.
This is what im trying to make:
You can apply filter to img instead of applying to entire div. I have added text in span elements, and set display: none; as default. On hover, you could change it to display: block;.
If you want to animate it as well, you can use opacity.
.container {
display: flex;
flex-wrap: nowrap;
width: 100vw;
height: 100vh;
justify-content: space-evenly;
}
.fern {
max-width: 50vw;
max-height: 100vh;
}
img {
max-width: 100%;
max-height: 80vh;
transition: .5s ease;
}
.venus {
max-width: 50vw;
transition: .5s ease;
}
.text{
display: none;
}
.venus:hover img {
-webkit-filter: blur(10px);
cursor: pointer;
}
.fern:hover img {
-webkit-filter: blur(10px);
transition: .5s ease;
cursor: pointer;
}
.fern:hover .text, .venus:hover .text{
display: block;
}
<body>
<h1 class="guide">
a guide to wellness and growth
</h1>
<div class="container">
<div class="fern">
<img src="https://www.pngjoy.com/pngm/48/1094382_ferns-ostrich-fern-transparent-png.png" alt="fern_nobg">
<span class="text">Fern</span>
</div>
<div class="venus">
<img src="https://assets.stickpng.com/images/580b585b2edbce24c47b2712.png" alt="venus_nobg">
<span class="text">Venus</span>
</div>
</div>
</body>

css bubble chat slide up animation

I'm trying to create chat animation using CSS only. So far, I have tried creating this. My question is how to hide a bubble when it's not their time to show up?
#keyframes slide {
from {bottom: -20px}
to {bottom: 0px}
0% { opacity: 0; }
100% { opacity: 1; }
}
Also, I figured that this is not the best approach to create chat animation. I still haven't thought about how to hide the older bubble chat when the chat is getting longer. Does anyone know what's the best approach to create this animation but using CSS only?
The key idea is to use a flexbox container which flex-direction: column-reverse so the messages are always bottom-anchored. Doing so you need to insert the markup of the whole chat in reverse order.
The container has a ::before pseudoelement stacked on top with a gradient as a background, so, while the conversation is scrolling, the messages seem to disappear on the top area.
The animation on the messages can be done using a different animation-delay for each message and animation-fill-mode: forwards to keep the values of the last keyframe.
*, *::before {
box-sizing: border-box;
}
.chat {
display: flex;
flex-direction: column-reverse;
height: 12rem;
overflow: hidden;
border: 1px #ccc dashed;
font: .85rem/1.5 Arial;
color: #313131;
position: relative;
}
.chat::before {
content: "";
position: absolute;
z-index: 1;
top: 0;
height: 40%;
width: 100%;
background: linear-gradient(to bottom, white 20%, rgba(255, 255, 255, 0)) repeat-x;
}
.chat p {
margin: 0;
padding: 0;
}
.chat__content {
flex: 0 1 auto;
padding: 1rem;
margin: 0 0.5rem;
background: var(--bgcolor);
border-radius: var(--radius);
}
.chat__message {
width: 45%;
display: flex;
align-items: flex-end;
transform-origin: 0 100%;
padding-top: 0;
transform: scale(0);
max-height: 0;
overflow: hidden;
animation: message 0.15s ease-out 0s forwards;
animation-delay: var(--delay);
--bgcolor: #d8d8d8;
--radius: 8px 8px 8px 0;
}
.chat__message_B {
flex-direction: row-reverse;
text-align: right;
align-self: flex-end;
transform-origin: 100% 100%;
--bgcolor: #d2ecd4;
--radius: 8px 8px 0 8px;
}
.chat__message::before {
content: "";
flex: 0 0 40px;
aspect-ratio: 1/1;
background: var(--bgcolor);
border-radius: 50%;
}
#keyframes message {
0% {
max-height: 100vmax;
}
80% {
transform: scale(1.1);
}
100% {
transform: scale(1);
max-height: 100vmax;
overflow: visible;
padding-top: 1rem;
}
}
<section class="chat">
<div class="chat__message chat__message_B" style="--delay: 18s;">
<div class="chat__content">
<p>Thank you.</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 13s;">
<div class="chat__content">
<p>Mr.Doe, your current balance is $19,606.76</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 10s;">
<div class="chat__content">
<p>Sure, let me check...</p>
</div>
</div>
<div class="chat__message chat__message_B" style="--delay: 6s;">
<div class="chat__content">
<p>Hi jane, I'm John Doe. <br />
I need to know my current account balance</p>
</div>
</div>
<div class="chat__message chat__message_A" style="--delay: 1s;">
<div class="chat__content">
<p>Hello, my name is Jane.<br />
How can I help you?</p>
</div>
</div>
</section>

CSS: flex-grow maintain vertical aspect ratio

I am creating a website with a circular menu. The website content should fit all onto the homepage without the need to scroll. The menu needs to fill the remaining space on the homepage. However, I am unsure how to maintain the shape of the circle while filling the remaining space on the homepage using flex-grow: 1. Is there a way I can do this with pure CSS? Setting the menu to a set viewport size is not acceptable, it needs to fill the remaining space. I am not having luck using the traditional padding-top: 100% to maintain aspect ratio. The circle is not quite circular and it takes up twice the remaining space.
body {
height: 100vh;
display: flex;
flex-direction: column;
margin: 0;
}
#title {
font-size: 30px;
}
#circle {
background: black;
border-radius: 50%;
flex-grow: 1;
padding-top: 100%;
}
#footer {
background: black;
color: white;
}
<body>
<div id="title">Title</div>
<div>navigation</div>
<div id="circle"></div>
<div id="footer">Footer</div>
</body>
Edit
I have figured out a way to maintain the aspect ratio of the circle filling the remaining space with flex grow. However, it is what I would consider a hack so I am leaving this question open.
body {
height: 100vh;
display: flex;
flex-direction: column;
margin: 0;
}
#title {
font-size: 30px;
}
#circle {
background: black;
border-radius: 50%;
flex-grow: 1;
/*width: max-content;*/
padding: 0%;
align-self: center;
}
#circle img {
height: 100%;
width: auto;
justify-content: center;
}
#footer {
background: black;
color: white;
}
<body>
<div id="title">Title</div>
<div>navigation</div>
<div id="circle"><img src="https://luxury.zappos.com/search/imgs/blank.20190219170746.png"></div>
<div id="footer">Footer</div>
</body>
Edit 2
It seems I was mislead by caniuse.com. This solution does not seem to work in most browsers besides chrome. Is there another solution?
Put the circle div inside a wrapper div in your HTML:
<div id="circle-wrap">
<div id="circle"></div>
</div>
Then move the flex rule to the wrapper:
#circle-wrap {
flex-grow: 1;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
margin: 0;
}
#title {
font-size: 30px;
}
#circle-wrap {
flex-grow: 1;
}
#circle {
background: black;
border-radius: 50%;
padding-top: 100%;
}
#footer {
background: black;
color: white;
}
<body>
<div id="title">Title</div>
<div>navigation</div>
<div id="circle-wrap">
<div id="circle"></div>
</div>
<div id="footer">Footer</div>
</body>

How do you expand a FlexBox item to full screen without moving the other Flex items?

I have a flexbox layout of boxes. The boxes expand to full screen when they are clicked on.
The problem is that when the box expands, it moves the other flex elements causing the animation to look jumpy. The flex layout also keeps the expanded box from touching the top of the screen.
Here is a fiddle to show you what I am talking about
fiddle
Box 1 is actually pretty close to the desired effect, but it still jumps around like I described above.
I have tried setting all of the unclicked cards to "display:none"; But that didn't solve either of the issues. I also tried to change the container to "display: block" when a card is expanded, and back to flex when it's not. But again, no luck
HTML
<div id=container>
<div class=cards>
<div class=card>
<div class="face front">
Card 1 Front
</div>
<div class="face back">
Card 1 Back
</div>
</div>
</div>
<div class=cards>
<div class=card>
<div class="face front">
Card 2 Front
</div>
<div class="face back">
Card 2 Back
</div>
</div>
</div>
<div class=cards>
<div class=card>
<div class="face front">
Card 3 Front
</div>
<div class="face back">
Card 3 Back
</div>
</div>
</div>
<div class=cards>
<div class=card>
<div class="face front">
Card 4 Front
</div>
<div class="face back">
Card 4 Back
</div>
</div>
</div>
</div>
CSS
body {
height:100vh;
width:100vw;
margin:0px;
}
.noDisplay{
display: none;
}
#container {
display: flex;
flex-flow: row wrap;
justify-content: center;
position: relative;
background: skyblue;
height:100%;
width: 100%;
overflow: hidden;
margin:auto;
}
.off {
color: rgba(0, 0, 0, 0.0) !important;
background: rgba(230, 230, 250, 0.0) !important;
-webkit-transition: all 2s; /* Safari */
transition: all 2s;
}
.cards {
width: 300px;
height: 300px;
border-radius: 5px;
margin-left: 25px;
margin-right: 25px;;
-webkit-perspective: 900px;
-moz-perspective: 900px;
perspective: 900px;
-webkit-transition: all 1s; /* Safari */
transition: all 1s;
}
.cards .card.flipped {
-webkit-transform: rotatey(-180deg);
-moz-transform: rotatey(-180deg);
transform: rotatey(-180deg);
height: 100%;
z-index: 100;
}
.cards .card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 1s; /* Safari */
transition: all 1s;
}
.cards .card .face {
width: 100%;
height: 100%;
position: absolute;
-webkit-backface-visibility: hidden ;
-moz-backface-visibility: hidden ;
backface-visibility: hidden ;
z-index: 2;
font-size: 2em;
font-family: arial, sans-serif;
text-align: center;
-webkit-transition: all 0.5s; /* Safari */
transition: all 0.5s;
}
.cards .card .front {
position: absolute;
background: tomato;
z-index: 1;
}
.cards .card .back {
-webkit-transform: rotatey(-180deg);
-moz-transform: rotatey(-180deg);
transform: rotatey(-180deg);
background: gold;
}
.cards .card .front,
.cards .card .back{
cursor: pointer;
}
.big {
height:100%;
width:100%;
top: 0%;
margin-left: 0%;
margin-right: 0%;
z-index:100;
}
jQuery
$('.card').click(function(){
if (!$(this).hasClass("flipped")) {
$( ".face" ).addClass( 'off' );
$( this ).children( ".face" ).removeClass( 'off' );
$( this ).parent( ".cards" ).addClass( 'big' );
$( this ).addClass('flipped');
/*$('.card').each(function(){
/*if(!$(this).hasClass('flipped')){
$(this).addClass('noDisplay');
}
});*/
} else {
$('.container').css('display', 'flex');
$( ".face" ).removeClass( 'off' );
$( ".cards" ).removeClass( 'big' );
$( this ).removeClass('flipped');
/*$('.card').each(function(){
$(this).removeClass('noDisplay');
});*/
}
});
Old question i know, but you can achieve this by changing the flex property on the siblings (when an item is clicked). First you need to set their size with flexbox, then say your cards are:
flex:1 0 33vh;
33vh being a third of the total viewport height; youd need to on click change the siblings (not the clicked one) to:
flex:0.00001;
(some say a small amount works better than flex:0; for transitions). That will set all cards but the clicked one to 0 height (or width, depending on the case) and the clicked one will expand to fill the total height of the viewport. Should you add overflow hidden and transition to the cards, you are golden.

Resources