?
Solved

CSS Animation

Posted on 2016-08-30
2
Medium Priority
?
67 Views
Last Modified: 2016-09-01
I am trying to transform .hero-text-box img to the bottom of page with fixed position. Here is the DEMO Thanks for any suggestion

.hero-text-box {
  position: fixed;
  width: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%)
}

.hero-text-box img {
  animation: example 3s 0s 1 forwards;
}

@keyframes example {
  0% {
    transform: scale(1) translateY(0);
  }
  100% {
    transform: scale(.5) translateY(-50px);
  }
}

Open in new window

0
Comment
Question by:mingchih
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 41777496
It seems that the positioning and the transform/translate are conflicting with one another. Remove the transform/translate, change the left position to 0 and add text-align: center. And change the bottom position to 10px.
.hero-text-box {
  position: fixed;
  bottom: 10px;
  left: 0;
  text-align: center;
  width: auto;
}

Open in new window

Text-align: center; centers the image horizontally in the div which is the width of the window. The left: 50%; and horizontal translate -50% were canceling each other anyway. The vertical translate 50% was overriding the bottom: 10px; style setting.

The issue now may be that the div is positioned at 10px from the bottom before the animation which scales from the center of the image. This leaves the image much more than 10px from the bottom of the screen after the animation. You may be able to compensate for that by changing the animation's translateY to move it down 50% of the original size, giving the appearance that the scale down is relative to the bottom center.
@keyframes example {
  0% {
    transform: scale(1) translateY(0);
  }
  100% {
    transform: scale(.5) translateY(50%);
  }
}

Open in new window

Please notice that the image has a significant amount of clear space around it which causes the actual position of the visible image to still be much more than 10px from the bottom of the window. The image would have to be edited to remove the extra clear space in order to get the visible part of the image to be 10px from the bottom of the window.
0
 

Author Closing Comment

by:mingchih
ID: 41780405
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question