I have sample code on codepen here
.liel{
position: relative;
}
.parent{
position: fixed;
top:0;
left:0;
width:100%;
height:100%;
background-color: rgba(0, 0, 0, .8);
z-index:100;
}
.green{
width:100px;
height:100px;
background-color:green;
}
#keyframes zoomIn {
0%{
top:0;
left:0;
width:100px;
height:100px;
opacity: 0;
}
100%{
opacity: 1;
}
}
.zoom{
width:200px;
height:200px;
background-color:red;
position: fixed;
top:50%;
left:50%;
transform: translate(-50%, -50%);
animation: zoomIn 5s;
}
<ul>
<li class="liel">
<div class="green"></div>
<div class="parent">
<div class="zoom"></div>
</div>
</li>
</ul>
There are 2 rectangles - one red and one green.
Green can be anywhere on the screen.
What I'm trying to create is zoom-in animation from position of green rectangle to the final position of red rectangle. I'm trying somehow to get starting position relative to green rectangle, but cannot do it since .parent element is also fixed in position.
Currently red element has zoom-in effect but initial position is left:0 top:0 which is position of .parent and not .green.
Is there any workaround for this?
May be this can help you. (Read this other stackoverflow answer)
$(document).ready(function() {
setTimeout( function(){
$('.green').addClass('fixed');
},1000);
$('.green').css('position','fixed');
});
.liel{
position: relative;
}
.parent{
position: fixed;
top:0;
left:0;
width:100%;
height:100%;
background-color: rgba(0, 0, 0, .2);
z-index:100;
pointer-events: none;
}
.green {
width:100px;
height:100px;
background-color:green;
transition: all 5s ease-in-out;
}
.zoom{
width:200px;
height:200px;
background-color:red;
position: fixed;
top:50%;
left:50%;
transform: translate(-50%, -50%);
animation: zoomIn 5s;
}
.fixed {
animation: zoomIn 5s;
transform: translate(-50%, -50%);
width:200px;
height:200px;
top:50%;
left:50%;
}
#keyframes zoomIn {
0%{
top:0;
left:0;
width:100px;
height:100px;
opacity: 0;
}
100%{
opacity: .5;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li class="liel">
<div class="green"></div>
<div class="parent">
<div class="zoom"></div>
</div>
</li>
</ul>
Related
In this code when, when rotating along top left point , the bar sways a lil bit down , while rotating
have seen this multiple time , sometimes it gets fixed , but i cannot spot the diff.
#keyframes rightup{
100%{
transition:transform 1s linear;
transform-origin:top left;
transform:rotate(-50deg);
}
}
.box{
position:absolute;
height:10px;
width:150px;
background-color:black;
top:50%;
left:50%;
border-radius:5px;
animation-name:rightup;
animation-duration:5s;
}
<div class="box"></div>
wanted something like this
.box{
position:absolute;
height:10px;
width:150px;
background-color:black;
top:50%;
left:50%;
border-radius:5px;
animation-name:rightup;
animation-duration:5s;
}
.box:hover{
transition:transform 1s linear;
transform-origin:top left;
transform:rotate(-50deg);
}
<div class="box"></div>
In the animation you aren't setting the transform-origin to the left top right from the start, but you are doing so in the transition/transform example.
Also, a minor point for such a slim bar but it makes a slight difference, you are rotating about the top of the bar rather than the (vertical) center.
This snippet changes both these things:
#keyframes rightup {
0% {
transform-origin: center left;
}
100% {
transform-origin: center left;
transform: rotate(-50deg);
}
}
.box {
position: absolute;
height: 10px;
width: 150px;
background-color: black;
top: 50%;
left: 50%;
border-radius: 5px;
animation-name: rightup;
animation-duration: 5s;
}
<div class="box"></div>
I am working on css animation transition.I have div id mybus. It's position is relative. It is the container of multiple divs position relative. I am trying to move the mybus which is the container of all other divs using animation transform: translateX(). It's not woking. (Question is, does position matter while animation?)
I separately applied animation which is transform: rotate() to the div class wheels (It is also inside mybus)which is working well. (I did't include this part of code ) I can give more info about code if needed.
.mybus{
position: relative;
animation-name:busgo;
animation-duration: 10s;
animation-iteration-count: 2;
animation-timing-function: linear;
/* animation-delay: 3s;*/
}
#keyframes busgo{
0%{
transform: translateX(20px);
}
100%{
transform: translateX(-1220px);
}
}
.busBody{
background-color: yellow;
position: absolute;
}
#front{
height:60px;
width:70px;
top:130px;
left:200px;
border-top-left-radius: 5px;
}
#back{
height:90px;
width:200px;
top:100px;
left:270px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.window{
height:20px;
width:30px;
background-color: dimgray;
position: absolute;
border-radius: 2px;
}
#w1{
top:110px;
left:300px;
}
#w2{
top:110px;
left:360px;
}
#w3{
top:110px;
left:420px;
}
<div id="mybus">
<div class="busBody" id="front"></div>
<div class="busBody" id="back"></div>
<div class="window" id="w1"></div>
<div class="window" id="w2"></div>
<div class="window" id="w3"></div>
<div class="wheel" id="wh1"></div>
<div class="wheel" id="wh2"></div>
<div class="headlight"></div>
</div>
You were using .mybus instead of #mybus
#mybus{
position: relative;
animation-name:busgo;
animation-duration: 10s;
animation-iteration-count: 2;
animation-timing-function: linear;
/* animation-delay: 3s;*/
}
#keyframes busgo{
0%{
transform: translateX(20px);
}
100%{
transform: translateX(-1220px);
}
}
.busBody{
background-color: yellow;
position: absolute;
}
#front{
height:60px;
width:70px;
top:130px;
left:200px;
border-top-left-radius: 5px;
}
#back{
height:90px;
width:200px;
top:100px;
left:270px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.window{
height:20px;
width:30px;
background-color: dimgray;
position: absolute;
border-radius: 2px;
}
#w1{
top:110px;
left:300px;
}
#w2{
top:110px;
left:360px;
}
#w3{
top:110px;
left:420px;
}
<div id="mybus">
<div class="busBody" id="front"></div>
<div class="busBody" id="back"></div>
<div class="window" id="w1"></div>
<div class="window" id="w2"></div>
<div class="window" id="w3"></div>
<div class="wheel" id="wh1"></div>
<div class="wheel" id="wh2"></div>
<div class="headlight"></div>
</div>
Here is a simple Js slider, and need to make it responsive for mobiles. But when i apply max-width to #slider and #image it hides whole div element. For example default width should be 500pxl and 300pxl height. For wide screen. It should automatically resize depend on mobile and tablet screen width. Is it possible?
html:
<body onLoad="photoA()">
<div id="slider">
<img src="Images/img1.jpg" id="image" >
<img onClick="photo(-1)" class="left" src="Images/arrow_left.png">
<img onClick="photo(1)" class="right" src="Images/arrow_right.png">
</div>
css:
*{
margin:0px;
}
#slider {
height:350px;
max-width:500px;
margin: 5px auto;
position:relative;
border-radius:4px;
overflow:hidden;
}
#image {
height:350px;
width:500px;
position:absolute;
}
.left {
height:50px;
width:50px;
position:absolute;
top:40%;
left:10px;
opacity:1;
transition: all .2s ease-in-out 0s;
}
.right {
height:50px;
width:50px;
position:absolute;
top:40%;
right:10px;
opacity:1;
transition: all .5s ease-in-out 0s;
}
.right:hover , .left:hover {
opacity:0.6; cursor: pointer;
}
What is the reason for positioning your main image absolutely? It will only make your life miserable.
If you make the following changes, you'll get the desired result:
#slider {
width: 100%;
max-width:500px;
height: auto;
margin: 5px auto;
position:relative;
border-radius:4px;
}
#image {
width: 100%;
height: auto;
}
To make your slider look even better, I suggest that you also use:
.left {
height:50px;
width:50px;
position:absolute;
top:50%;
transform: translateY(-50%);
left:10px;
opacity:1;
transition: all .2s ease-in-out 0s;
}
.right {
height:50px;
width:50px;
position:absolute;
top:50%;
transform: translateY(-50%);
right:10px;
opacity:1;
transition: all .5s ease-in-out 0s;
}
Note: The div disappeared because you cannot set max-width to the parent when all its children are positioned absolutely With no widths and heights or max-widths and max-heights (They behave as if they had the values not set).
This question already has answers here:
Expanding a parent <div> to the height of its children
(20 answers)
Closed 8 years ago.
I'm trying to set the height of .background based on the number of .slice elements on the page. I know the inner elements being floated left doesn't help but I'm not sure how to solve this.
JSFiddle
http://jsfiddle.net/8ryAD/
HTML
<div class="master">
<a id="btn-nav">
<span></span>
<span>Menu</span>
<span></span>
</a>
<nav id="main-nav">
<div class="background">
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
<div class="slice"></div>
</div>
</nav>
</div><!-- end master -->
CSS
#import url(http://fonts.googleapis.com/css?family=Droid+Sans);
body {
background: #2980b9;
font-family: 'Droid Sans', sans-serif;
}
#btn-nav {
position:absolute;
left:10px;
top:10px;
width:30px;
height:30px;
display:block;
z-index:1;
}
#btn-nav:hover {
cursor:pointer;
}
#btn-nav span:nth-child(2) {
top:10px;
}
#btn-nav span:nth-child(3) {
top:20px;
}
#btn-nav span {
height: 4px;
width: 30px;
background: white;
content: "";
text-indent: -999em;
display:inline-block;
position:absolute;
zoom: 1;
top:0px;
left:0px;
text-align:center;
-webkit-transition: top .3s cubic-bezier(0.165,.84,.44,1);
-webkit-transform: rotate(0deg);
}
#btn-nav:hover > span, #btn-nav.open > span {
top:10px;
}
#btn-nav.open > span:nth-child(1) {
-webkit-animation: rotateAni .2s .1s forwards, expandAni .3s .3s forwards;
}
#btn-nav.open > span:nth-child(2) {
-webkit-animation: rotateAni .2s .1s forwards, expandAni-2 .3s .3s forwards;
}
#btn-nav.open > span:nth-child(3) {
-webkit-animation: rotateAni .2s .1s forwards, expandAni-3 .3s .3s forwards;
}
#-webkit-keyframes rotateAni {
0% {-webkit-transform: rotate(0deg);}
100% {-webkit-transform: rotate(90deg);}
}
#-webkit-keyframes expandAni {
0% {left:0;}
100% {left:-10px;}
}
#-webkit-keyframes expandAni-2 {
0% {left:0;}
100% {left:0px;}
}
#-webkit-keyframes expandAni-3 {
0% {left:0;}
100% {left:10px;}
}
#main-nav {
position:fixed;
left:0;
top:0;
display:block;
width:100%;
height:100%;
z-index:-1;
}
.slice {
width:25%;
height:30%;
min-height:30%;
float:left;
background:black;
opacity:0;
-webkit-transition: 1s;
}
.background {
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
z-index:-1;
}
Managed to do it; deleted the layout and started again.
The main thing was to set overflow hidden on the master div and give it a min-height.
Followed the answers here: Expanding a parent <div> to the height of its children
#master {
background: #000;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
width: 100%;
}
#main-nav {
left: 0;
position: absolute;
top: 0;
display: block;
height: 100%;
position: fixed;
width: 100%;
z-index: -1;
}
.slice {
background: #000;
float: left;
height: 33.66%;
opacity: 0;
filter: alpha(opacity=0);
width: 25%;
-webkit-transition: 1s;
}
After much Googling and fiddling with various different options, I'm struggling to get my CSS3 Animation to behave in the way I want it to!
Let me start with the code
<html>
<head>
<style>
body
{
overflow:hidden;
margin:0px;
}
.about
{
overflow:hidden;
width:400%;
height:95%;
background:#10b4ff;
position:absolute;
animation-name:contentPane;
animation-duration:5s;
animation-timing-function:ease;
animation-delay:0s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:contentPane;
-webkit-animation-duration:5s;
-webkit-animation-timing-function:ease;
-webkit-animation-delay:0s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
}
#keyframes contentPane
{
0% {background:#eeeeee; left:0px; top:0px;}
33% {background:#10b4ff; left:-100%; top:0px;}
66% {background:#eeeeee; left:-200%; top:0px;}
100% {background:#10b4ff; left:-300%; top:0px;}
}
#-webkit-keyframes contentPane
{
0% {background:#eeeeee; left:0px; top:0px;}
33% {background:#10b4ff; left:-100%; top:0px;}
66% {background:#eeeeee; left:-200%; top:0px;}
100% {background:#10b4ff; left:-300%; top:0px;}
}
.menuMarker{
width:20px;
height:20px;
border:2px solid #fff;
background:#fff;
border-radius:50%;
bottom:7%;
position:absolute;
/* Animation */
animation-name:menuMarker;
animation-duration:5s;
animation-timing-function:ease;
animation-delay:0s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:menuMarker;
-webkit-animation-duration:5s;
-webkit-animation-timing-function:ease;
-webkit-animation-delay:0s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
}
#keyframes menuMarker
{
0% {background:#10b4ff; border:#eeeeee 2px solid; border-radius:50%; left:12.5%;}
33% {background:#eeeeee; border:#10b4ff 2px solid; border-radius:30%; left:37.5%;}
66% {background:#10b4ff; border:#eeeeee 2px solid; border-radius:50%; left:62.5%;}
100% {background:#eeeeee; border:#10b4ff 2px solid; border-radius:30%; left:87.5%;}
}
#-webkit-keyframes menuMarker
{
0% {background:#10b4ff; border:#eeeeee 2px solid; border-radius:50%; left:12.5%;}
33% {background:#eeeeee; border:#10b4ff 2px solid; border-radius:30%; left:37.5%;}
66% {background:#10b4ff; border:#eeeeee 2px solid; border-radius:50%; left:62.5%;}
100% {background:#eeeeee; border:#10b4ff 2px solid; border-radius:30%; left:87.5%;}
}
.one{
width:25%;
height:100%;
left:0px;
top:0px;
position:absolute;
color:#10b4ff;
}
.two{
width:25%;
height:100%;
left:25%;
top:0px;
position:absolute;
color:#eeeeee;
}
.three{
width:25%;
height:100%;
left:50%;
top:0px;
position:absolute;
color:#10b4ff;
}
.four{
width:25%;
height:100%;
left:75%;
top:0px;
position:absolute;
color:#eeeeee;
}
.menuOne{
border-top:2px #fff solid;
left:0%;
width:25%;
height:5%;
bottom:0px;
background:#10b4ff;
position:fixed;
}
.menuTwo{
border-top:2px #fff solid;
left:25%;
width:25%;
height:5%;
bottom:0px;
background:#eeeeee;
position:fixed;
}
.menuThree{
border-top:2px #fff solid;
left:50%;
width:25%;
height:5%;
bottom:0px;
background:#10b4ff;
position:fixed;
}
.menuFour{
border-top:2px #fff solid;
left:75%;
width:25%;
height:5%;
bottom:0px;
background:#eeeeee;
position:fixed;
}
</style>
</head>
<body>
<div class='about'>
<div class='one'>Test 1</div>
<div class='two'>Test 2</div>
<div class='three'>Test 3</div>
<div class='four'>Test 4</div>
</div>
<div class='menuMarker'></div>
<div class='menuOne'><center>About</center></div>
<div class='menuTwo'>Gallery</div>
<div class='menuThree'>Showreel</div>
<div class='menuFour'>Contact</div>
</body>
</html>
So here's the thing. I tried to add make all the animation-play-state properties "paused" and then add:
menuOne:hover
{
animation-name:menuMarker;
animation-play-state:running;
}
Problem is, this predictably makes the menuOne class behave as if it's the marker. What I'm looking for is a way of hovering over the different menu items (menuOne, menuTwo etc) and have the marker move to it's position over that item.
Am at a complete loss, and would LOVE some help!
Thanks guys and gals!
First, don't use center tags. There are much better ways to position things in the middle, in your case that would be giving the menus text-align:center;
The closest you can get using your pure CSS animation is something like this, where the animations pause when the menu is hovered over. Your animation runs in a loop, and currently in CSS3 you're not allowed to restart the animation at a different point, so you can't do it well.
That being said, you can add simple transitions ALONG with your animation and get a much more desirable result like this one! It has some glitches, but you can likely play around with it to get a little bit smoother. But again, since CSS3 does not allow animations to be started mid-animation, it won't be perfect. If you used javascript as well it could be done a fair bit smoother, but you didn't mention that in your question
Here is the updated CSS and slightly modified HTML
<html>
<head>
<style>
body {
overflow:hidden;
margin:0px;
}
.about {
overflow:hidden;
width:400%;
height:95%;
background:#10b4ff;
position:absolute;
animation-name:contentPane;
animation-duration:15s;
animation-timing-function:ease;
animation-delay:0s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:contentPane;
-webkit-animation-duration:15s;
-webkit-animation-timing-function:ease;
-webkit-animation-delay:0s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
transition: all .5s linear;
-webkit-transition: all .5s linear;
}
#keyframes contentPane {
0% {
background:#eeeeee;
left:0px;
}
33% {
background:#10b4ff;
left:-100%;
}
66% {
background:#eeeeee;
left:-200%;
}
100% {
background:#10b4ff;
left:-300%;
}
}
#-webkit-keyframes contentPane {
0% {
background:#eeeeee;
left:0px;
}
33% {
background:#10b4ff;
left:-100%;
}
66% {
background:#eeeeee;
left:-200%;
}
100% {
background:#10b4ff;
left:-300%;
}
}
.menuMarker {
width:20px;
height:20px;
border:2px solid #fff;
background:#fff;
border-radius:50%;
bottom:7%;
position:absolute;
/* Animation */
animation-name:menuMarker;
animation-duration:15s;
animation-timing-function:ease;
animation-delay:0s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:menuMarker;
-webkit-animation-duration:15s;
-webkit-animation-timing-function:ease;
-webkit-animation-delay:0s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
transition: all .5s linear;
-webkit-transition: all .5s linear;
}
#keyframes menuMarker {
0% {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:12.5%;
}
33% {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:37.5%;
}
66% {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:62.5%;
}
100% {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:87.5%;
}
}
#-webkit-keyframes menuMarker {
0% {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:12.5%;
}
33% {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:37.5%;
}
66% {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:62.5%;
}
100% {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:87.5%;
}
}
.one {
width:25%;
height:100%;
left:0;
top:0;
position:absolute;
color:#10b4ff;
}
.two {
width:25%;
height:100%;
left:25%;
top:0;
position:absolute;
color:#eeeeee;
}
.three {
width:25%;
height:100%;
left:50%;
top:0;
position:absolute;
color:#10b4ff;
}
.four {
width:25%;
height:100%;
left:75%;
top:0;
position:absolute;
color:#eeeeee;
}
.menu {
position:absolute;
bottom:0;
text-align:center;
width:25%;
height:5%;
background:#10b4ff;
}
.menuOne {
left:0;
}
.menuTwo {
left:25%;
}
.menuThree {
left:50%;
}
.menuFour {
left:75%;
}
.menu:nth-child(even) {
background:#eeeeee;
}
.menu:hover ~ .menuMarker {
animation:none;
-webkit-animation: none;
}
.menu:hover ~ .about {
animation: none;
-webkit-animation:none;
}
.menuOne:hover ~ .about {
background:#eeeeee;
left:0px;
}
.menuTwo:hover ~ .about {
background:#10b4ff;;
left:-100%;
}
.menuThree:hover ~ .about {
background:#eeeeee;
left:-200%;
}
.menuFour:hover ~ .about {
background:#10b4ff;
left:-300%;
}
.menuOne:hover ~ .menuMarker {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:12.5%;
}
.menuTwo:hover ~ .menuMarker {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:37.5%;
}
.menuThree:hover ~ .menuMarker {
background:#10b4ff;
border:#eeeeee 2px solid;
border-radius:50%;
left:62.5%;
}
.menuFour:hover ~ .menuMarker {
background:#eeeeee;
border:#10b4ff 2px solid;
border-radius:30%;
left:87.5%;
}
</style>
</head>
<body>
<div class='menu menuOne'>About</div><!--
--><div class='menu menuTwo'>Gallery</div><!--
--><div class='menu menuThree'>Showreel</div><!--
--><div class='menu menuFour'>Contact</div>
<div class='about'>
<div class='one'>Test 1 </div>
<div class='two'>Test 2</div>
<div class='three'>Test 3</div>
<div class='four'>Test 4</div>
</div>
<div class='menuMarker'></div>
</body>
</html>
I changed your HTML structure because you use position:absolute anyway and it made selecting the .about and .menuMarker easier
Side note: You don't have to declare the same top:0px; for your animations. If you don't tell it to change it won't. Also in CSS if you have a pixel value of 0 you can leave it off if you'd like, aka top:0 = top:0px
If you have any questions let me know!