CSS3 animation/keyframes, transforming with vw in IE11 issues - css

I'm animating an element across a screen, but in IE11, weird things are happening. I'm in development, so I can't share the live code. But I created a fiddle to replicate the problem.
Basically, when I use viewport width aka vw with transform:translateX(); inside a #keyframes to use in an animation, IE11 doesn't reflect the width of the viewport in the animation.
So the Fiddle I created takes an element that is positioned in the center of the viewport:
starts it at the left edge of the screen with half of the element
appearing
moves to the center of the viewport, pauses
and then moves to the right edge of the viewport, with half the element off of the screen
Fiddle: https://jsfiddle.net/Bushwazi/7xe0wy8z/4/
In the website I'm working on, IE11 animates the element as if the
page were 10 times wider
In the fiddle, the animation runs in reverse
and never makes it to the edge of the page.
So in both cases, IE11 isn't using the correct width for vw inside CSS animations.
HTML:
<!--
The animation on the red block should start half on the screen, pause at the center of the screen and then finish by pausing at the edge of the screen, half of the box off of the screen
-->
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<strong><span>BLOCK</span></strong>
</article>
CSS:
* {
margin: 0;
padding: 0;
}
#-webkit-keyframes movee {
0% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
10% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
40% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
60% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
90% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
100% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
}
#keyframes movee {
0% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
10% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
40% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
60% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
90% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
100% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
}
body {
background-color: #eee;
background-image: -webkit-linear-gradient(left, black 50%, transparent 50.01%);
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
font-family: sans-serif;
height: 100vh;
}
article {
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
-webkit-animation: movee 5.0s linear infinite 0.0s;
animation: movee 5.0s linear infinite 0.0s;
}

According to caniuse:
In IE 10 and 11, using vw units with 3D transforms causes unexpected behavior
Although 2D & 3D transforms are different, it is likely that they are handled by simliar methods within a browser. So I would say that VW/VH/VMAX/VMIN are not supported in IE11 for transitions.
Is there any reason you don't want to use % ?
Like this:
* {
margin: 0;
padding: 0;
}
#-webkit-keyframes movee {
0% {
left: -1%;
}
10% {
left: -1%;
}
40% {
left: 50%;
}
60% {
left: 50%;
}
90% {
left: 101%;
}
100% {
left: 101%;
}
}
#keyframes movee {
0% {
left: -1%;
}
10% {
left: -1%;
}
40% {
left: 50%;
}
60% {
left: 50%;
}
90% {
left: 101%;
}
100% {
left: 101%;
}
}
body {
background-color: #eee;
background-image: -webkit-linear-gradient(left, black 50%, transparent 50.01%);
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
font-family: sans-serif;
height: 100vh;
}
article {
border: thin dotted green;
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
-webkit-animation: movee 5.0s linear infinite 0.0s;
animation: movee 5.0s linear infinite 0.0s;
}
<!--
The animation on the red block should start half on the screen, pause at the center of the screen and then finish by pausing at the edge of the screen, half of the box off of the screen
-->
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<strong><span>BLOCK</span></strong>
</article>

One posibility would be to use transform as percentages.
Since you want the amout of the transform to be 100vw, lets set an extra element with a width of 100vw. Now, the transform on this element is just 100%.
I had to use negative offsets to avoid the appearance of an undesired horizontal scrollbar
* {
margin: 0;
padding: 0;
}
#keyframes movee {
0% {
transform: translateX(-100%)
}
10% {
transform: translateX(-100%)
}
40% {
transform: translateX(-50%)
}
60% {
transform: translateX(-50%)
}
90% {
transform: translateX(0%)
}
100% {
transform: translateX(0%)
}
}
body {
background-color: #eee;
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
height: 100vh;
}
article {
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
.base {
width: 100vw;
animation: movee 5.0s linear infinite 0.0s;
top: 50%;
position: absolute;
height: 100px;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
right: 0px;
top: 0px;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
}
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<div class="base">
<strong><span>BLOCK</span></strong>
</div>
</article>

Related

Animate button with two backgrounds

Im trying to do the same button but without the need to make hover (running the animated background all the time).
I've tried different approach like using background-clip, shadows, etc but unfortunately without success.
Maybe if I use another element like a div and span can work but I really want to do it with a button.
Codepen
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background: #000;
}
.glow-on-hover {
width: 220px;
height: 50px;
border: none;
outline: none;
color: #fff;
background: #111;
cursor: pointer;
position: relative;
z-index: 0;
border-radius: 10px;
}
.glow-on-hover:before {
content: '';
background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
position: absolute;
top: -2px;
left: -2px;
background-size: 400%;
z-index: -1;
filter: blur(5px);
width: calc(100% + 4px);
height: calc(100% + 4px);
animation: glowing 20s linear infinite;
opacity: 0;
transition: opacity .3s ease-in-out;
border-radius: 10px;
}
.glow-on-hover:active {
color: #000
}
.glow-on-hover:active:after {
background: transparent;
}
.glow-on-hover:hover:before {
opacity: 1;
}
.glow-on-hover:after {
z-index: -1;
content: '';
position: absolute;
width: 100%;
height: 100%;
background: #111;
left: 0;
top: 0;
border-radius: 10px;
}
#keyframes glowing {
0% {
background-position: 0 0;
}
50% {
background-position: 400% 0;
}
100% {
background-position: 0 0;
}
}
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<button class="glow-on-hover" type="button">HOVER ME, THEN CLICK ME!</button>
What is making your ::before pseudo-element to hide when it's not hovered is opacity:0. If you remove it, you will have the desired effect. Also, you might want to remove the glow-on-hover:hover:before selector since it's not going to be any use.

Tricky CSS Positioning Animation

I'm learning about CSS animations and am trying to animate this stamp which uses relative and absolute positioning. I want the animation to:
Start at it's original size.
Grow 2-3xs that size and be at the center of the screen.
Pause for 2-3 seconds seconds.
Shrink back down to it's original size and spot.
The problem I'm running into is keeping the elements positioned on top of the stamp in the same place as the transitions occur. Looking to keep it pure CSS if possible (*side note I haven't added any web-kit/browser support yet because I'm just trying to make it work first).
Here is the code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
height: 90vh;
justify-content: flex-end;
align-items: flex-start;
background: grey;
}
.park-img {
width: 10rem;
height: 11.2rem;
display: inline-block;
margin-left: 2px;
padding: 10px;
background: white;
position: relative;
top: 2rem;
left: -2rem;
/*-webkit-filter: drop-shadow(0px 0px 10px rgba(0,0,0,0.5));
/*The stamp cutout will be created using crisp radial gradients*/
background: radial-gradient( transparent 0px, transparent 4px, white 4px, white);
/*reducing the gradient size*/
background-size: 20px 20px;
/*Offset to move the holes to the edge*/
background-position: -10px -10px;
/*Animation*/
animation: stampAnimation 9s ease-in-out;
}
#keyframes stampAnimation {
0% {}
50% {
transform: scale(3, 3) translate(-35%, 35%);
}
75% {
transform: scale(3, 3) translate(-35%, 35%);
}
}
.stampText {
position: relative;
top: -1rem;
left: -1.8rem;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
color: #fafafa;
text-transform: uppercase;
animation: stampAnimation 9s ease-in-out;
}
.park-name {
font-weight: bold;
text-align: center;
font-size: 1rem;
}
.park-title {
width: 90%;
overflow: hidden;
text-align: center;
font-size: .5rem;
}
.park-title:before,
.park-title:after {
background-color: #fafafa;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 10%;
}
.park-title:before {
right: 0.5rem;
margin-left: -50%;
}
.park-title:after {
left: 0.5rem;
margin-right: -50%;
}
<div class="park-stamp">
<img src="https://res.cloudinary.com/saveallthethings/image/upload/v1614633821/daniel-burka-X_IwSPO2GH0-unsplash_zvoyst.jpg" class="park-img" />
<div class="stampText">
<div class="park-name">Zion</div>
<div class="park-title">National Park</div>
</div>
</div>
As well as the codepen:
https://codepen.io/aspirationalhobbit/pen/GRNPqxw?editors=0100
I have edited your code to make changes that are different from my initial answer.
Check https://codepen.io/udabasili/pen/VwmqmQK?editors=1100.
Basically, I created a css for the container of your element and moved the animation there. I also removed the translate from your animation. Check the css in the codepen to see the changes
.park-stamp{
animation: stampAnimation 9s ease-in-out infinite;
}

How to slide modal windows from left and right of page

I wish to have two modal windows hidden, and toggle them to slide in from the left, and another to slide in from the right.
In the fiddle I have created, the left, and right, modal windows align correctly to the left and right of the page, however. The left modal slides in from right instead of sliding "out" from the left margin.
Fiddle Here
When I try to have the left modal window slide from the left, I lose the slide-out effect.
#rightModal .modal-dialog-slideout {
min-height: 100%;
margin: 0 0 0 auto;
background: #fff;
}
#rightModal .modal.fade .modal-dialog.modal-dialog-slideout {
-webkit-transform: translate(100%, 0)scale(1);
transform: translate(100%, 0)scale(1);
}
#rightModal .modal.fade.show .modal-dialog.modal-dialog-slideout {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
display: flex;
align-items: stretch;
-webkit-box-align: stretch;
height: 100%;
}
#rightModal .modal.fade.show .modal-dialog.modal-dialog-slideout .modal-body {
overflow-y: auto;
overflow-x: hidden;
}
#rightModal .modal-dialog-slideout .modal-content {
border: 0;
}
#rightModal .modal-dialog-slideout .modal-header,
.modal-dialog-slideout .modal-footer {
height: 69px;
display: block;
}
#rightModal .modal-dialog-slideout .modal-header h5 {
float: left;
color: blue;
}
#leftModal .modal-dialog-slideout {
min-height: 100%;
margin: 0 auto 0 0;
background: #fff;
}
#leftModal .modal.fade .modal-dialog.modal-dialog-slideout {
-webkit-transform: translate(-100%, 0)scale(1);
transform: translate(-100%, 0)scale(1);
}
#leftModal .modal.fade.show .modal-dialog.modal-dialog-slideout {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
display: flex;
align-items: stretch;
-webkit-box-align: stretch;
height: 100%;
}
#leftModal .modal.fade.show .modal-dialog.modal-dialog-slideout .modal-body {
overflow-y: auto;
overflow-x: hidden;
}
#leftModal .modal-dialog-slideout .modal-content {
border: 0;
}
#leftModal .modal-dialog-slideout .modal-header,
.modal-dialog-slideout .modal-footer {
height: 69px;
display: block;
}
#leftModal .modal-dialog-slideout .modal-header h5 {
float: left;
color: red;
}
How to maintain the slide-out effect, and maintain positions of the two modals?
You need to translate .modal-dialog -100% on the x-axis when the modal is not shown.
The modal has .show class when it is displayed. Use the :not() CSS pseudo-class to select the modal in its hidden state.
The :not() CSS pseudo-class represents elements that do not match a
list of selectors. Since it prevents specific items from being
selected, it is known as the negation pseudo-class. - https://developer.mozilla.org
#leftModal.modal.fade:not(.show) .modal-dialog.modal-dialog-slideout {
-webkit-transform: translate(-100%,0)scale(1);
transform: translate(-100%,0)scale(1);
}
https://jsfiddle.net/r25uphq3/

flexbox not aligning :after & :before correctly in firefox and safari

I'm working on a loading animation. My issue is that centering these with flexbox only seems to work correctly in Chrome. The :before & :after are at the bottom of their parent div in Firefox, and at the top in safari.
#pulse-box {
width: 100%;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
#pulse {
position: relative;
width: 12.5px;
height: 50px;
animation: pulse 750ms infinite;
animation-delay: 250ms;
display: flex;
justify-content: center;
align-items: center;
}
#pulse:before,
#pulse:after {
content: '';
position: absolute;
display: block;
width: 12.5px;
height: 33.3px;
background: #efefef;
animation: pulse 750ms infinite;
}
#pulse:before {
left: -25px;
/* -(pulse height / 1.5) */
}
#pulse:after {
left: 25px;
/* (pulse height / 1.5) */
animation-delay: 500ms;
}
#keyframes pulse {
0%,
10% {
background: #efefef;
}
50% {
background: #5b5b5b;
}
}
<div id="pulse-box">
<div id="pulse" />
</div>
You can also see this in the jsfiddle I made.
Give this a go...
#pulse::before, #pulse::after {
content: '';
position: absolute;
display: block;
width: 12.5px;
height: 33.3px;
background: #efefef;
animation: pulse 750ms infinite;
top: 50%;
transform: translateY(-50%);
}
https://jsfiddle.net/opt4jmmt/

CSS3-After-Element-Transformation not working cross browser?

i think my implementation of an animated hexagon has several cross-browser-problems:
http://jsbin.com/mojavowapi/1/edit?css,output
.hexagon {
position: relative;
width: 173px;
height: 300px;
background-image: url(https://live.tlprod.de/temp/glas.jpg);
background-size: auto 100%;
background-position: 50% 50%;
transition: all 2s linear;
margin-left: auto;
margin-right: auto;
}
.hexagon:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
background: inherit;
}
.hexLeftBox, .hexRightBox {
overflow: hidden;
transform: scaleY(1.6) rotate(-45deg);
background: inherit;
top: 27.9%;
position: absolute;
display: inline-block; /* let the block get the width of the containing image */
z-index: 1;
height: 44%;
}
.hexLeft, .hexRight {
width: auto;
height: 100%; /* get full height of parent element, set width to aspect ratio 1:1 */
}
.hexLeftBox {
transform: scaleY(1.6) rotate(-45deg) translate(-35.5%,-35.5%);
}
.hexRightBox {
right: 0;
transform: scaleY(1.6) rotate(-45deg) translate(35.5%,35.5%);
}
.hexLeftBox:after, .hexRightBox:after {
content: "";
position: absolute;
width: 142%;
height: 142%;
transform: rotate(45deg) scaleY(1) scaleX(1.6) translate(-50%,0%);
transform-origin: 0 0;
background: inherit;
transition: all 2s linear;
}
.hexLeftBox:after {
background-position: -7% top;
}
.hexRightBox:after {
background-position: 107% top;
}
.hexagon:hover {
width: 300px;
height: 350px;
}
.hexagon:hover .hexLeftBox:after {
background-position: -35% top;
}
.hexagon:hover .hexRightBox:after {
background-position: 135% top;
}
.hexagon2 {
width: 300px;
height: 350px;
margin-top: 40px;
}
.hexagon2 .hexLeftBox:after {
background-position: -35% top;
}
.hexagon2 .hexRightBox:after {
background-position: 135% top;
}
In this example the above hexagon changes on hover to the -same- size as the other loaded with.
In Chrome 50 the background image of the after-elements disappear AND the aspect ratio crashes
In IE 11 only the aspect ratio of the edges crashes
In Firefox 46 all works fine
..but the funny thing: In all Browser the second static version with the same values as the hover is working fine.
Are there some problems known and fixable?
The crashed aspect ratio is a webkit-optimizing-issue.
It could be fixed only with switching to a javascript-animation with forcing the rerendering via:
$('body').css('display', 'table').height();
$('body').css('display', 'block');
And with jQuery you can do this in the progress-Parameter of the animate()-function.
Switching to a javascript-animation also eleminates the disappearing after-elements.

Resources