i need to implement load/unload page animations fade-in on load, and fade-out on unload.
1) I have read some articles about implementation it based on links clicks. That's does not work for me. I don't want to go that way, because some links should not open new page actually, and have href.
So imagine: link has properly href, but sometimes it open new page, sometimes not, based on it handler behavior. We add another handler that fire redirect all the time as timeout callback.
2) I can't implement animation using page unload event. I think it's right way.
Please help or advice something. Thank You!
Give your links you want to animate a class. Then you can use the .click() method to check when a link is clicked. Then do a preventDefault to stop the default behavior.
The next thing to do is check if there is "http" in the href attribute. You can get the value with $(this).attr('href');. If the link contains this, you need to go to a new page. For this, use window.location.href. Call this method as the callback of your fadeOut().
The only thing that is left is do a fade in when the page loads ;)
Actually i was finding the way without using links event, but using any UNLOAD event. Links events can be used only on a small website. In my case it created additional errors. For example some links, shouldn't do fade-out, and i don't know which of them actually.
So i don't recommend to do this. Need to find any UNLOAD page redirections animation way.
I'm not sure if I understand your question correctly..
Put this code in the pages' <head>s.
<style>
#keyframes page_transition
{
from {opacity: 0;}
to {opacity: 1;}
}
#-webkit-keyframes page_transition
{
from {opacity: 0;}
to {opacity: 1;}
}
html
{
animation: page_transition 1s ease-in-out;
-webkit-animation: page_transition 1s ease-in-out;
}
html.unloading
{
transition: opacity 500ms linear !important;
opacity: 0 !important;
}
</style>
<script>
window.addEventListener("beforeunload", function() {
document.documentElement.classList.add("unloading");
});
</script>
Related
I do not know if I can link to the theme that has the problem that I
want to solve. If it is not allowed, please tell me to delete the
question
I'm using this theme:
here
And as you can see, whenever the cursor is on the sidebar, it expands. How can I make the sidebar only get bigger when the cursor is on the sidebar for at least 2 seconds? That a delay occurs before the animation.
Is there any part in the javascripts used by the theme where I can define this delay?
A bit of CSS will do it.
To delay only the opening:
.sidebar-visible .icon-thumbnail,
.sidebar-visible .page-sidebar,
body.sidebar-visible .page-sidebar .sidebar-header .sidebar-header-controls {
transition-delay: 2s;
}
To delay both opening and closing:
.icon-thumbnail,
.page-sidebar,
.page-sidebar .sidebar-header .sidebar-header-controls,
body.sidebar-visible .page-sidebar .sidebar-header .sidebar-header-controls {
transition-delay: 2s;
}
Note this CSS has to be loaded after theme's to work properly.
You can do so using setTimeout.
When the user hovers the sidebar, start a timeout, at the end of the timeout, check if they are still hovering the sidebar. If so, call the function to pop out the menu.
Try use jquery
.mouseout();
for example:
$("p").mouseout(function(){
$("p").delay(5000).hide(1000);
});
Any one know a good library for elements entering animation while page scrolling. I have used animate it library, its awesome, lite and easy to handle but not working with newest version of jQuery(3.x).
Somebody suggest me a good free library.
You may try animate-on-scroll:
https://michalsnik.github.io/aos/
Or if you need a more advanced library with lot more control in your hands, try ScrollMagic:
http://scrollmagic.io/
you can use Animate.css and Wow.js
You could use the onscroll event handler.
window.onscroll - function() {
var el = document.getElementById('animateMe');
el.addClass('anime');
}
where you have the animation included in the .anime class.
CSS
.anime {
animation: yourAnimation 2s ease-out;
}
#keyframes animation {
0% {
background: blue;
}
100% {
backgroudn: red;
}
}
If you need the animation to stop when not scrolling, see How do I know when I've stopped scrolling Javascript.
I am building my first site and really wanted a button which wiggled. I was doing some research and i found the perfect button that i want.
Link
If you scroll down to the end of the page. The way the download button looks is exactly what i wanted. However for some reason i been playing around with the code and i dont get any sort of animation to appear. No idea why this is. If possible could someone show me the way on how to code this?
Thanks
Sorry forgot the code:
#-webkit-keyframes wiggle {
0% {
-webkit-transform:rotate(4deg);
}
50% {
-webkit-transform:rotate(-4deg);
}
100% {
-webkit-transform:rotate(4deg);
}
}
.wiggle:hover {
-webkit-animation: wiggle 0.5s infinite;
}
This is not from the site, this is my trying , but it does not get the right effect which is the same as the download button. I am actually really stuck on this hahaha :) So any help on this would be great x
You could check their animations from here https://elrumordelaluz.github.io/csshake/css/csshake.css to get a clue.
I have a dialog in which I'd like to display one of two things depending on the state of a variable. So, I hooked up 2 versions of a form with ng-if.
When you click "delete" button on first state, it toggles to the second state.
I wanted to make it less abrupt, so I tried adding some css:
[ng-if].ng-enter {
animation: fadeIn .5s;
}
[ng-if].ng-leave {
animation: fadeOut .5s;
}
These animations come from the bower package "animate css":
#keyframes fadeIn {
0% {opacity: 0;}
100% {opacity: 1;}
}
.fadeIn {
animation-name: fadeIn;
}
However, as you can see in my animated GIF below, what happens is that for a second BOTH forms appear, making the dialog taller, then one fades out.
Is there no way to do a simple fadein/fadeout as in jQuery? I used to do this all the time with it, but trying to get nice UI animation in Angular is eluding me.
I had a similar problem with an Angular app and animations. I ended up having to use jquery - I wish I had a better answer - but it turned out beautifully. One note, though, I had to wrap any jquery I used in a noConflict() and use body on click plus the element because it doesn't exist yet in the DOM:
$.noConflict();jQuery( document ).ready(function( $ ) {
$('body').on('click', "#toggler", function(){
$('#div_to_show').slideDown();
});
});
I realize this a tangential answer and not an elegant solution but it worked for me to get it out the door under a tight deadline.
A clean solution is to change the state you use to check which form is to display when the animation ng-leave ends.
You can use a second variable to set the ng-leave class in the form that will be hidden.
I can't post you some code because i don't know your js and html.
I have this jsFiddle. When the button is clicked, I want to put the red div behind the black one immediately, then start the animation.
var red = document.getElementById("red");
var button = document.getElementById("button");
button.addEventListener("click",function () {
red.style.zIndex = -1;
red.classList.remove("shifted");
});
However, as you can see, they seem to be occurring as two separate actions. I know I can use setTimeout to wait until the zIndex property is applied, but I do not know how long I am supposed to wait, and the duration perhaps differs from browsers to computers.
Should I create a loop that will check if zindex was applied? But this also sounds like an unintelligent solution. What is the correct way?
EDIT: I do not want to change the zIndex on the black div.
You can bind to the transitioned state of the element, something like this:
("#mySelector").bind("transitionend", function(){ 'yourcodehere' });
Also, here is some info on it:
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_transitions
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/transitionend
Without jQuery:
el.addEventListener("transitionend", updateTransition, true);
Edit:
There was some confusion as to the usage of:
-webkit-transition-duration: 1s;
This is applied like a styling as well. So anytime you make alterations to the element it is on, you are triggering this. You have TWO transition calls, one for setting the z-index, another for the movement.
Just put a
-webkit-transition-property: -webkit-transform;
into the #red and everything is fine. ;) This applies the transition only to specified property.
JSFIDDLE: http://jsfiddle.net/Qvh7G/.
The problem is with zIndex - the transform time delays the change in the zIndex.
You can simply force the duration for the transform property.
Replace:
-webkit-transition-duration: 1s;
With
-webkit-transition: -webkit-transform 1s; // ease-in;