Angular UI Router: ui-view positioning on state change - angularjs

I am currently developing a heavy angular-driven homepage for an agency. Now I am at the state-change. I added a page transition with a simple fade effect. Now the problem I have is, that the new ui-view that is being added when the state changes is prepended before the first ui-view. Everything alright, but as the first ui-view is fading out the second is already added and the transition looks just crappy. So, I want to have the new ui-view added after the first ui-view.
IMPORTANT: I am using parallax effects, so the solution with a page-container and absolute positioning isn't possible.
This image is showing what I want to have afterwards.

I had faced similar issue, it was because I had animation on both enter and leave.
You dont need animation on both enter and leave.
You can have animation only on leave or only on enter
E.g.
.ng-enter {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
opacity: 0;
}
checkout the easing in animation in this PLUNKER
OR if you want animation in both enter and leave, then add a delay in animation
add delay to your transitions:
.ng-enter{
-webkit-transition: all 2s ease 1s;
-moz-transition: all 2s ease 1s;
-o-transition: all 2s ease 1s;
transition: all 2s ease 1s;
}
.ng-leave {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}

Building off of #HarishR's answer:
http://plnkr.co/edit/pzsDd1zPvHgdZe099upi?p=preview
We have 2 transitions:
IN:
.ng-enter {
transition: opacity 1s ease; // autoprefixer
opacity: 0; // start animating
}
.ng-enter-active {
opacity: 1; // end animating
}
OUT:
.ng-exit {
transition: opacity 1s ease; // autoprefixer
opacity: 1; // start animating
}
.ng-exit-active {
opacity: 0; // end animating
}
This will take 1 second to fade in and out the blocks. When there's only 1 block, it fades in immediately over 1 second. What if there are two blocks though (transitioning from one to another?). We can use delays and some nifty css:
// Selector only matches if 2 sibling animating elements exist
.ng-animate + .ng-animate {
// Avoid pushing around DOM
// Property disappears once the first sibling leaves
position:absolute;
// Delay fade-in until first sibling leaves
transition-delay: 1s; // autoprefixer
}
Without this fancy selector, the first time you open a view you'd have a 1s delay before anything happens.

Related

Converting css with nested classes to styled components problem

I'm having problems understanding nesting in styled components, i have a code i need to implement in my project but i don't fully understand how to write the same stuff with styled-comp. due to nesting of classes..
CSS:
#cf {
position:relative;
height:281px;
width:450px;
margin:0 auto;
}
#cf img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#cf img.top:hover {
opacity:0;
}
HTML:
<div id="cf">
<img class="bottom" src="/images/Cirques.jpg" />
<img class="top" src="/images/Clown%20Fish.jpg" />
</div>
I've been using styled-components for couple of weeks, so i understand the basics, i'm just having problems writing 2 nested objects like it's shown in css...
If u got time to explain it a bit, would be great :)
it becomes:
import Styled from 'styled-components';
const MyDiv = Styled.div`
position:relative;
height:281px;
width:450px;
margin:0 auto;
img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
&.top:hover{
opacity:0;
}
}
`
 Render
<MyDiv />
Working example
https://codesandbox.io/s/xj3y2qz87q
Looking at the documentation for Pseudoelements, pseudoselectors, and nesting, you could use your existing CSS as is as that would be how you would apply effects such as :hover anyway. Here is what that would look like applying your existing CSS to a styled-component:
const Foo = styled.div`
#cf {
position:relative;
height:281px;
width:450px;
margin:0 auto;
}
#cf img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#cf img.top:hover {
opacity:0;
}
`;
Usage of the styled-component:
<Foo>
<div id="cf">
<img className="bottom" src="https://via.placeholder.com/200/0000FF/808080" />
<img className="top" src="https://via.placeholder.com/200/FF0000/FFFFFF" />
</div>
</Foo>
Here is an example in action.
Hopefully that helps!
When you implement your style rules, you might be surprised when they are not applied as expected. The reason is how the styled_components works behind the scenes:
it creates a <style> tag with attribute data-styled="active" and adds it to the <head> element
it adds a random class name to the element being styled before any class names that you have added
then it adds the style rules to its own <style> element, preceded by the random class name
This results in the style rule selector that works only for selector components that are in your element or children of your element.
But say you need to override a style rule in another stylesheet, that has a component with an id (i.e. preceded by #) from a parent DOM element. You cannot use that #{some-id} selector in the rule you add to the styled component, because the order of the selector created for you begins with that random class name. In this case, to get the selector to have the precedence required, you will have to nest another element (probably a div) with an #id, and use that #id in your style rule.

Unwanted ≥ showing in Lightbox2

How can I remove the "≥" link button (and the line it occupies) which appears above my thumbnails when using Lightbox2? I have checked through the CSS which accompanies the js and cannot find it anywhere.
In the lightbox2 CSS sheet the images that attach to those white next link buttons can be found in this block of code. Don't forget to remove it from the states like a:hover. You can always go to other websites for similar png files to change the slider options for nav left and right.
.lb-nav a.lb-prev {
width: 34%;
left: 0;
float: left;
background: url(../images/prev.png) left 48% no-repeat;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;
-webkit-transition: opacity 0.6s;
-moz-transition: opacity 0.6s;
-o-transition: opacity 0.6s;
transition: opacity 0.6s;
}
.lb-nav a.lb-prev {
width: 34%;
left: 0;
float: left;
background: url(../images/prev.png) left 48% no-repeat;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;
-webkit-transition: opacity 0.6s;
-moz-transition: opacity 0.6s;
-o-transition: opacity 0.6s;
transition: opacity 0.6s;
}

ng-Animate doesn't remove add classes angular 1.2.x

I am trying to have an icon animate while loading and stop the animation once loading is complete. I was attempting this by activating a class based on a refreshing property. This worked in AngularJS 1.2.0-rc.3, but now (have tried 1.2.3 and 1.2.4) the animation never stops, and I believe the reason is that the -add classes that are added are not removed when the bound variable changes to false.
Here is the plunker demonstrating.
http://plnkr.co/edit/fbcCPxwZtcIoS0ZqrHhf?p=preview
Interesting that more toggles of the variable eventually do stop the animation. Is what I am trying to do valid, I suppose I could always just show hide a loading gif, but I liked the idea of animating the existing image
Thanks!
Curt
The problem is in your css.
You don't need '.icon-refresh-animate-add'.
Use this css class:
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}
It's a carbon copy of your animate-add.
Explanation: The ngClass is turning the .icon-refresh-animate class on and off. So when the state is true the class is applied and the animation loops forever. When the state is false the css class is removed so there will be no animation at all. So this bit of code does all the work for you
ng-class="{'icon-refresh-animate':refreshing}"
And here's the full CSS:
#keyframes rotateThis {
from {
transform: scale(1) rotate(0deg);
}
to {
transform: scale(1) rotate(360deg);
}
}
#-webkit-keyframes rotateThis {
from {
-webkit-transform: scale(1) rotate(0deg);
}
to {
-webkit-transform: scale(1) rotate(360deg);
}
}
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}

AngularJS 1.2 fade animation from 0 to 0.5 not working

So I have this simple fade animation using AngularJS 1.2 and the ngAnimate module but I'm having a small issue.
I want to show/hide an element with a fade animation but I want the element to fade from opacity: 0 to opacity: 0.5. The thing is, the element fades from 0 to 0.5 within the duration period I set, but after the animation ends, it sets the opacity to 1. I don't want that.
This is my CSS code:
.overlay {
background-color: #ff0000;
position: absolute;
width: 150px;
height: 150px;
}
.fade-animation.ng-hide-add, .fade-animation.ng-hide-remove {
transition: 2s linear all;
display: block !important;
}
.fade-animation.ng-hide-remove {
opacity: 0;
}
.fade-animation.ng-hide-remove.ng-hide-remove-active {
opacity: .5;
}
.fade-animation.ng-hide-add {
opacity: .5;
}
.fade-animation.ng-hide-add.ng-hide-add-active {
opacity: 0;
}
Here's a sample of the problem: http://jsfiddle.net/Kn3th/8/
I'm testing this on Firefox.
That's because as soon as the animation completes, the animation-related classes are removed, so only the .overlay definition applies. Just add this to your CSS:
.overlay {
...
opacity: .5; // <-- add this line to apply an opacity of 0.5
} when the animation is over
See, also, this short demo.

ngHide and ngAnimate with max-width: transition property on the wrong class?

I'm using ngAnimate to animate max-height for a simple slide-toggle effect, and there's something a bit strange happening: when hiding, it seems that setting the transition property on the setup class (.xxx-hide) doesn't work--the height snaps to 0 immediately:
.controls-hide {
-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;
max-height: 5em;
opacity: 1;
}
.controls-hide.controls-hide-active {
max-height: 0em;
opacity: 0;
}
But setting it on the active class (.xxx-hide.xxx-hide-active), the animation works just fine:
.othercontrols-hide {
opacity: 1;
max-height: 5em;
}
.othercontrols-hide.othercontrols-hide-active {
-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;
max-height: 0em;
opacity: 0;
}
(Here's the whole fiddle.)
Even more strangely, the opacity animates just fine in both cases. What's going on here?
I just follow the instructions at this site: http://www.nganimate.org/angularjs/ng-repeat/appear
And I got this fiddle working: http://jsfiddle.net/WXWSu/2/
What I changed was set the transtion tag to all changes (transition: 1s linear all;), and set the start properties at the main class:
.exercise-controls {
overflow: hidden;
border: 1px solid black;
height: 5em;
opacity: 1;
}

Resources