CSS Animation from right to left dynamically - html

The problem I'm facing is:
I have a animated text which goes from right to left, this text change depending on the languague set, what is causing that the total width of the text changes too.
In this picture, the effect I want is working fine, because some properties are fixed.
Now, when I change for a longer text the problem cames up.
So, this is what I have now:
And this is what I'd like to have:
Here is the code I'm using:
ReactJS Side:
constructor(props) {
super(props);
this.state = {
checked: false
}
}
componentDidMount() {
window.addEventListener('scroll', () => {
if (event.srcElement.body.scrollTop >= 1400) {
this.setState({ checked: true });
}
});
}
render() {
return (
<div>
... stuff
<span style={{ fontSize: "40px", color: this.state.theme.COLOR_3 }}>
<input type="checkbox" id="Resume-chk" style={{ display: "none" }} checked={this.state.checked} />
<b id="Resume-title">{this.state.languageSet.RESUME}</b>
</span>
... more stuff
<div>
);
}
CSS Side:
//This is the text
#Resume-title {
display: inline-block;
-webkit-transition: color 200ms ease-in;
-moz-transition: color 200ms ease-in;
transition: color 200ms ease-in;
-webkit-transition: right 500ms ease-in;
-moz-transition: right 500ms ease-in;
transition: right 500ms ease-in;
position: relative;
right: -40.5%;
}
//This is the text when the checkbox is checked
#Resume-chk:checked ~ #Resume-title {
right: 40.5%;
}
So, the question is: How to fix it? Or maybe there is some concept I'm missing and it is a little bit more than just fixing a bug.
Also I'm not sure if doing things like right: -40.5%; and right: 40.5%; is a good practice, but I cant find a way to animate property like float or align.
Of course, if there is a way to fix it, but also there is a way to do it even better, It is also welcome!!!
EDITED: here the fiddle containing the whole html section, copied from dev console

You need a combination of positioning with right and a transform.
This is an usual idea for centering an element, adapted to your request:
.container {
width: 300px;
background-color: lime;
margin: 10px;
position: relative;
}
.item {
display: inline-block;
position: relative;
right: -100%;
transform: translateX(-100%);
transition: right 1s, transform 1s;
}
.container:hover .item {
right: 0%;
transform: translateX(0%);
}
<div class="container">
<div class="item">Item</div>
</div>
<div class="container">
<div class="item">Item long</div>
</div><div class="container">
<div class="item">Item longer longer</div>
</div>

Related

Trigger multipe 'transitions' at the same time

Does anybody know how to play transitions from two separate Components
with the same styling at the same time.
Here is a video, which shows my problem.
https://youtu.be/WNu4Mdfn98U
Important CSS Parts
.Container_Active .Description {
max-height: 500px;
margin-top: 5px;
color: var(--ifm-color-on-primary);
transition: max-height 1000ms ease-in; /* Transiation 1 */
}
.Description {
max-height: 0;
margin: 0;
font-size: var(--ifm-font-size-18);
overflow: hidden;
transition: max-height 1000ms ease-out; /* Transiation 2 */
}
Important HMTL Parts
<div
className={clsx(styles.Container, {
[styles.Container_Active]: active,
})}
>
</div>
<SectionRightItem
key={i}
title={section.title}
description={section.description}
onClick={() => {
setIndex(i);
}}
icon={section.icon}
active={index === i}
/>
My goal is that the one element slowly shows the description and the other element slowly hides the expanded description at the same time.
But somehow the transitions are played in a row, although they are triggered at the same time.
Thank you ^^
Actually your animation is starting at the same time, but the problem is that you use the transition of max-height with a value that's too high, so the transition will start from the height of 500px to 0px, but your content height doesn't even reach half of it, so it appears like there's a delay between your transition
To resolve the problem, you can lower the value of .Container_Active to match your actual description height, or change it to height rather than max-height with an average height of your actual description
Here's a simple snippet about the difference between max-height (light blue) and height (red) for the transition which makes your transition looks like it's delayed, both height / max-height is set to 0 when not opened and 10em when opened
$(function() {
setInterval(function() {
$('div').toggleClass('open');
}, 1500);
});
div {
position: absolute;
}
#front {
max-height: 0;
overflow: hidden;
background: lightblue;
transition: max-height 1000ms ease-in-out;
padding-left: 3em;
}
#front.open {
max-height: 10em;
transition: max-height 1000ms ease-in-out;
}
#back {
height: 0;
background: red;
transition: height 1000ms ease-in-out;
opacity: .75;
}
#back.open {
height: 10em;
transition: height 1000ms ease-in-out;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='front' class='open'>
Hello World Welcome<br/>World</br>Welcome
</div>
<div id='back' class='open'>
BACK
</div>

Reducing and enlarging text from a single point

I'm trying to make an animation. The essence of the animation is that when scrolling down, the text decreases, and if up, it increases. And when scrolling down it should remain fixed. But I have a problem: when you zoom in and out, the text is not linked to any point, so it is more clear to attach a gif
An example of how it should be: Click
An example of what actually happens: Click
HTML
<div class="main__logo">
<h1 id="logo">
Fashion
</h1>
</div>
CSS
.main__logo {
font-size: 200px;
position: fixed;
margin-top: 0;
}
.main__logo .logo__sticky {
position: fixed;
font-size: 24px;
margin-top: -80px;
}
#logo {
-webkit-transition: all .4s ease;
-o-transition: all .4s ease;
transition: all .4s ease;
}
jQuery
$(window).scroll(function () {
if ($(this).scrollTop() > 80) {
$("#logo").addClass("logo__sticky");
} else {
$("#logo").removeClass("logo__sticky");
}
});
I suggest you use animate it will make it easier for you to animate every frame just like the video.

CSS-ReactJS Animation when an element gets visible

I don't know if what I want is possible with pure CSS, I'd prefer to avoid using JQuery because I'm building my app with ReacJS.
I have the following effect
.container {
display: flex;
flex-direction: column;
}
#box {
display: inline-block;
width: 100px;
height: 100px;
background-color: red;
transition: all 800ms ease-in;
position: relative;
right: calc(100px - 100%);
}
#chk:checked ~ #box{
right: 0;
}
<div class="container">
<label>check the input to see the effect</label>
<br/>
<input id="chk" type="checkbox">
<div id="box"></div>
</div>
It works when an input (checkbox) is checked, the thing is I want to reproduce the same effect but when an element is shown in the screen.
Why not to use JQuery?
As I'm building my app using ReactJS, using JQuery is not recommended neither the community nor Facebook.
I'd like to use CSS some React component, but I don't know how.
Check my own answer to see how I figured it out
Why don't you create a class instead of selector with checked property and then toggle the class with react.
Using CSS + ReactJS I solved doing this:
I used a checkbox to check or uncheck depending on where the scroll is. Then using CSS just change where the text is being rendered.
CSS Code:
#WhoIAm-title {
display: inline-block;
-webkit-transition: all 800ms ease-in;
-moz-transition: all 800ms ease-in;
transition: all 800ms ease-in;
position: relative;
right: -38%;
}
#WhoIAm-chk:checked ~ #WhoIAm-title {
right: 38%;
}
ReactJS Code:
componentDidMount() {
window.addEventListener('scroll', () => {
if (event.srcElement.body.scrollTop >= 620 && event.srcElement.body.scrollTop <= 650) {
this.setState({ checked: true });
}else if (event.srcElement.body.scrollTop >= 820 || event.srcElement.body.scrollTop <= 600) {
this.setState({ checked: false });
}
});
}
render() {
return (
<div id="whoiam" className="Container column">
<span>
<input type="checkbox" id="WhoIAm-chk" style={{ display: "none" }} checked={this.state.checked} />
<b id="WhoIAm-title">Title to toggle to right</b>
</span>
</div>
);
}

Unwanted animation on page load with angularjs

I have a page with an element that has an animation on hide/show. The page loads when the element is not shown but still, when the page loads it shows the hide animation.
I've even tried to change the condition to ng-show="false" and still I see the hide animation when page loads.I've understood that there was an old problem with angularjs about this but I'm using 1.2.2.
HTML:
<div class="c_redDiv" ng-show="state == true">
<div ...>
<button ...>
<div ... />
</button>
<button ...>
<div ... />
</button>
</div>
</div>
CSS:
.c_redDiv.ng-hide-add, .c_redDiv.ng-hide-remove {
-webkit-transition: all linear 0.5s;
-moz-transition: all linear 0.5s;
-o-transition: all linear 0.5s;
transition: all linear 0.5s;
display: block !important;
}
.c_redDiv.ng-hide-add.ng-hide-add-active,
.c_redDiv.ng-hide-remove {
opacity: 1;
top: -50px;
}
.c_redDiv.ng-hide-add,
.c_redDiv.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
top: 0px
}
you should add to your css:
.c_redDiv{
display:none;
}
.c_redDiv.ng-show{
display:block;
}
I was unable to find a way to avoid the initial animation triggering when ng-hide or ng-show is used, but was able to get it working with ng-if.
HTML:
<div class="c_redDiv" ng-if="state == true">
...
</div>
SASS:
.c_redDiv {
overflow: hidden;
transition: max-height 0.35s ease;
&.ng-leave, &.ng-enter.ng-enter-active {
max-height: 300px;
}
&.ng-leave.ng-leave-active, &.ng-enter {
max-height: 0;
}
}

Hovering over one div triggers another div

How would I go about hovering over an image that then blurs the background image behind it within css? The way I have it set up now is the background image blurs upon hover.
Here's my css:
.blur img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.blur img:hover {
-webkit-filter: blur(5px);
}
.wrapper{
width:900x;
height: 100px;
position: absolute;
top: 2400px;
z-index: 50;
}
.logo{
postion: absolute;
margin: 0 auto;
top: 2420px;
z-index: 50;
left: 400px;
}
html:
<div class="blur"><img src="/homepic1.jpg"></div>//This is the image I want blurred
<div class="wrapper">
<div class="row">
<div class="span12 pagination-centered">
<img src="/transparanetsnu.png">//How do I hover over any of these images to trigger a blur on "homepic1.jpg"
</div>
<div class="span4 offset3">
<div class="box2"><img src="/greek_logo.gif"></div>
</div>
<div class="logo"><img src="/UM-Main-Logo-Maroon.gif">
</div>
I think the best way is to use JQuery. All images and add a class like 'blur' to them everytime user hover over one image, but you should remove the class from the one you don't want.
$('.img1').mouseover(function(){
$('img').addClass('blur');
$('.img1').removeClass('blur');
});
Add the effect using css or javascript.
Use jQuery for that purpose.
First of all dowload jQuery from: http://code.jquery.com/jquery-1.10.2.min.js
Then.
$('.yourImage').mouseover(function(){ //'.yourImage' are the last three images in your case.
$('.homepic1').addClass('blur'); //'.homepic1' is the class of first image in your case
});
.addClass('blur') , Will add the class 'blur' from your CSS to that '.homepic1' element, As soon as your mouse hovers over ANY of the three images.