I have a few divs on my view which need to be animated.
I created some CSS like this:
.pk-image-container {
position: relative;
height: 625px;
.animate-hide {
position: absolute;
left: 0;
opacity: 1;
transition: all ease 1s;
height: 625px;
width: 100%;
&.ng-hide {
left: -100%;
opacity: 0;
}
}
}
The view looks like this:
<div class="pk-image-container" ng-if="!multiple">
<div class="animate-hide" ng-repeat="answer in question.answers track by $index" ng-hide="$index !== currentSlide"></div>
</div>
So far that gives me a sliding effect fading in from the left and then fading out to the left.
But I want to do something a little better.
I would like the active item to fade in from the left, but the inactive one to fade out to the right.
Can this be done using ng-hide or animate.css?
You could use an additional class of .active on your items and set left: 0.
Otherwise, you can set all items to left: 100%.
To set the class, you can use ng-class.
CSS:
.pk-image-container {
position: relative;
height: 625px;
.animate-hide {
position: absolute;
left: 100%;
opacity: 1;
transition: all ease 1s;
height: 625px;
width: 100%;
&.ng-hide {
left: -100%;
opacity: 0;
}
&.active {
left: 0;
}
}
}
HTML:
<div class="pk-image-container" ng-if="!multiple">
<div ng-class="[animate-hide, {'active': $index === currentSlide}]" ng-repeat="answer in question.answers track by $index" ng-hide="$index !== currentSlide"></div>
</div>
I found a better way of doing it.
I used ngAnimate and I did it like this:
.pk-image-container {
position: relative;
height: 625px;
.slide {
position: absolute;
left: 0;
width: 100%;
height: 625px;
}
.slide.ng-enter {
transition: 0.3s linear all;
left: 100%;
}
/* The finishing CSS styles for the enter animation */
.slide.ng-enter.ng-enter-active {
left: 0;
}
/* now the element will fade out before it is removed from the DOM */
.slide.ng-leave {
transition: 0.3s linear all;
}
.slide.ng-leave.ng-leave-active {
left: -100%;
}
}
and updated the HTML to this:
<div class="pk-image-container" ng-if="!multiple">
<div class="slide" ng-repeat="answer in question.answers track by $index" ng-if="$index === currentSlide"></div>
</div>
Related
I'm currently working on a module in HTML/CSS and JS.
In my code I have 4 images in absolute position. I would like 1 of them to move (with animations) in front of the others.
My HTML code looks like that :
<section class="bar-container">
<img id="oyster">
<img class="waves" id="wave-1">
<img class="waves" id="wave-2">
<img class="waves" id="wave-3">
<div class="progression-bar">
some stuff
</div>
</section>
And my CSS code looks like this :
.bar-container {
position: relative;
}
.bar-container #oyster {
position: absolute;
left: 8.5%;
top: 38%;
animation: 2s ease infinite slideup;
transition: left 1.5s;
z-index: 4;
}
.bar-container #wave-1 {
position: absolute;
top: 60%;
left: 14%;
opacity: 1;
z-index: 3;
}
.bar-container #wave-2 {
position: absolute;
top: 60%;
left: 39%;
opacity: 1;
z-index: 2;
}
.bar-container #wave-3 {
position: absolute;
top: 60%;
left: 64%;
opacity: 1;
z-index: 1;
}
The fact is that my oyster is behind the waves and I tried a lot of different combinaisons but it still not working as i would like to...
Here is the result
I really don't know how to do what I would like... Can someone help me ?
I have a sidebar menu with logo toggle button which toggles the class "toggled" and on large screens also appears on hover.
The sidebar is left: 100% and on toggle/hover left: 0;
On all browsers except safari it works fine. Only on safari the logo button wiggles/shakes when letting the navigation appear.
Here a short overview of the code:
.main-navigation {
//Structure
display: inline-block;
width: 160px;
transition: all 250ms ease-in;
height: 100vh;
z-index: 100;
position: fixed;
left: -100%;
background-color: $color__primary;
&.toggled {
left: 0;
}
.menu-toggle {
margin-left: auto;
align-self: flex-end;
display: inline-block;
position: fixed;
background: none;
border: none;
border-radius: 0;
left: 20px;
top: 25px;
width: auto;
height: auto;
padding: 0;
z-index: 110;
&:focus, &:active {
outline: none;
}
}
}
And on large screens i just add the hover:
.main-navigation{
&:hover {
left: 0;
}
}
You can see it live under https://rocket.creos.agency/
I hope im just overlooking something small.
Thanks for the help!
In order to fix your problem you need to move your 'logo' from the nav element. If it is inside, like you have it's trying too animate all elements inside nav.
Here is your logic with simple code (logo is inside nav):
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav:hover {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
.content {
margin-top: 50px;
}
<nav>
<button>
Hover me
</button>
<div class='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
And this is when 'logo' is outside the nav:
(() => {
const btn = document.getElementById('animateNav');
const nav = document.getElementById('navigation');
const content = document.getElementById('content');
btn.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
nav.addEventListener('mouseout', () => {
nav.classList.remove("animate");
});
nav.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
content.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
})();
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav.animate {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
#content {
margin-top: 50px;
}
<nav id='navigation'>
<div id='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
<button id='animateNav'>
Hover me
</button>
All difference is in second example that you need to toggle a class for nav using JavaScript. I provided not efficient logic to toggle a class, but I just wanted to present to you working solution.
P.S. don't use <a> tag inside of <button> tag
I have an element on screen that i would like to go full screen. I have done this, by using the following css
.fullscreen {
z-index: 2000;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
padding: 15px;
background-color: white;
}
Now i would like to have a nice animation when my element is clicked, so it looks a bit sexy as it maximizes and the same when it minimizes.
Can this be done??
I have tried transition: top .15s linear; but that doesnt seem to work
NOTE
I cannot have the element start with position:fixed using css, unless i had to use javascript to toggle it, as this is a normal html element, so i do not always want it fixed.
here is the fiddle where i got the css from to go fullscreen, so you can see what i mean. http://jsfiddle.net/a7nzy6w6/1/
The position property can't be animated. If you start with position: fixed, it's no problem.
Fiddle: http://jsfiddle.net/a7nzy6w6/299/
#myDiv.fullscreen {
z-index: 9999;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
#myDiv {
position: fixed;
width: 500px;
height: 400px;
top: 20px;
left: 20px;
transition: all .15s linear;
background: #cc0000;
}
Note that using JavaScript you could find the position on the page and set it to fixed at the position as to not have to start with position: fixed, but that's outside the scope of this question.
Following up on comments to include a fade transition with CSS transition and jQuery for class toggles:
CSS:
#myDiv.fullscreen {
z-index: 9999;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#myDiv.fade {
opacity: 0;
}
#myDiv {
width: 500px;
height: 400px;
top: 20px;
left: 20px;
background: #cc0000;
transition: opacity .15s linear;
}
JS:
$('button').click(function(e) {
var $div = $('#myDiv');
$div.toggleClass('fade');
setTimeout(function(){
$div.toggleClass('fade fullscreen');
}, 150);
});
Fiddle: http://jsfiddle.net/a7nzy6w6/308/
You need to use transition
$('button').click(function(e){
$('#myDiv').toggleClass('fullscreen');
});
#myDiv{
background:#c99;
top: 0;
left: 0;
position: fixed;
width:500px;
height:400px;
transition: all 1s ease;
}
#myDiv.fullscreen{
z-index: 9999;
width: 100%;
height: 100%;
transition: all 1s ease;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>
Try this
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>
#myDiv.fullscreen{
z-index: 9999;
min-width: 100%;
min-height: 100%;
position: fixed;
top: 0;
left: 0;
}
#myDiv{
background:#cc0000;
min-width:500px;
max-width: 500px;
min-height:400px;
transition: all 500ms;
}
live demo - http://jsfiddle.net/a7nzy6w6/306/
I have an idea for an Ajax-loader.
This is what I have accomplished so far:
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
I want the moving indicator (.dark-bar) to be "melted" with foreground-div. Currently there is a hard line which is visually distinguishable.
Is there a way to get the moving indicator (.dark-bar) to be blurred on the left-, right edge?
You could make use of CSS filter to add blur to top layer which is animated as below,
filter - The filter property provides graphical effects like blurring,
sharpening, or color shifting an element. Filters are commonly used to
adjust the rendering of images, backgrounds, and borders.
Do include vendor prefixes for other browsers such as -webkit-,-o-,-moz-,-ms- to filter.
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
-webkit-filter:blur(2px); /*Add this*/
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
Try using the box-shadow property and set the vertical and horizontal axis values to 0. Something like this:
div {
box-shadow: 0 0 10px black;
}
This might be a similar effect for the one you want.
I have implemented the off-canvas sidebar template from Twitter Bootstrap in my project and made it fixed in small / medium 'view'. Problem is i'm trying to fix it for xs but it really just disappears.
How can i make it fixed properly?
css
html,
body {
max-width: 100%;
overflow-x: hidden; /* Prevent scroll on narrow devices */
}
body {
padding-top: 70px;
}
.sidebar-offcanvas {
position: fixed;
top: 50px;
right: 0;
height: 100%;
width: 200px;
}
.sidebar-offcanvas, .sidebar-offcanvas a {
background-color: #ECF0F1;
border: none;
}
/*
* Off Canvas
* --------------------------------------------------
*/
#media screen and (max-width: 767px) {
.row-offcanvas {
position: relative;
-webkit-transition: all .5s ease-out;
-o-transition: all .5s ease-out;
transition: all .5s ease-out;
}
.row-offcanvas-right {
right: 0;
}
.row-offcanvas-left {
left: 0;
}
.row-offcanvas-right
.sidebar-offcanvas {
right: -50%; /* 6 columns */
}
.row-offcanvas-left
.sidebar-offcanvas {
left: -50%; /* 6 columns */
}
.row-offcanvas-right.active {
right: 50%; /* 6 columns */
}
.row-offcanvas-left.active {
left: 50%; /* 6 columns */
}
.sidebar-offcanvas {
position: fixed;
top: 0;
width: 50%;
}
}
html
<div class="container">
<div class="row row-offcanvas row-offcanvas-right">
<div class="col-xs-12 col-sm-9 col-md-10">
<my-notification></my-notification>
<div ui-view></div>
</div>
<div class="sidebar-offcanvas" id="sidebar">
<div class="list-group">
.. omitted
</div>
</div>
</div>
</div>
I'm not exactly sure what you were trying with your CSS but your problem is
.row-offcanvas-right
.sidebar-offcanvas {
right: -50%; /* 6 columns */
}
in combination with
.sidebar-offcanvas {
position: fixed;
top: 0;
width: 50%;
}
This causes the .sidebar-offcanvas to be 50% wide and then its right position starts at minus 50%. This causes the element effectively to disappear as it gets pushed out of the screen by its total width to the right. So dependent on what you want to achieve you need to change right: -50%; to something else like right: 0px; for instance.
default (via .show on .offcanvas). Offcanvas includes support for a header with a close button and an optional body class for some initial padding. We suggest that you include offcanvas headers with dismiss actions whenever possible, or provide an explicit dismiss action.