I have the following animation setup in JQuery, I want the opacity to slowly climb to 100% in 4 seconds and there after fall back to 0% quickly. The result i see is the opposite, fast opacity up, and slow fade. What Is my mistake?
$(motorProtectionElementWarning).animate({
opacity:1,
duration: 4000
},{
complete: function(){ $(motorProtectionElementWarning).animate({opacity:0},1000);}
},5000);
Give it a shot with this syntax :
$(motorProtectionElementWarning).animate({
opacity:1,
}, 4000, function(){
$(motorProtectionElementWarning).animate({opacity:0},1000);
});
I edit your code and its worked.
$(".test").animate({
opacity:0,
duration: 10000
},{
complete: function(){
$(".test").animate({opacity:1},5000);}
},5000);
test it : http://jsfiddle.net/mehmetakifalp/m75YU/
Related
I'm foolin around with the jquery hover functionality. the current code snippet looks like this:
$leftColumn.children().first().hover(
function(event) {
var $this = jQuery(this);
$this.css({
'background-color': '#505050'
}).parent().stop()
.animate(
{
'z-index': '999',
width: '220px'
},
{
duration: '1000'
}
);
},
function(event) {
var $this = jQuery(this);
$this.parent().stop()
.animate(
{
width: '38px',
'z-index': '1'
},
{
duration: '1500',
complete: function() {
$this.css({
'background-color': 'transparent'
});
}
}
);
}
);
What this basically does is increasing the width of a div (which is position absolute) to overlay another div.
I choosed to use jQuerys animate() functionality instead of CSS3s transition because I want to trigger a callback whenever the closing (decreasing the width again) animation is done.
My problem now is, that I want to delay the closing animation for 2 seconds (and yes I know about the delay() vs setTimeout() discussion) which worked fine with setTimeout(). However as the animation is timed out for the given duration it will run, even if I enter the hoverable area again. This of course makes sense as the stop() only triggeres while an animation is on the go, which is not the case if it is timed out.
How can I make this thing work (stop the closing animation when reentering the hoverable area) and still keep a timeout / delay before decreasing the width on "hover leave"?
I have a simple slide down function using jQuery where I'm simply animating an image to slide down. It works great. However I'm trying to reset the animation after it's ran, so it will continue on loop during the duration of the users session. I tried the below, but it didn't work as wanted, slide animation still ran, but not the sought effect of timing out and restarting. Thanks for any thoughts.
$(window).load(function () {
setTimeout(function(){
$("#man").show("slide", {
direction: "up"
}, 2000);
},500);
});
You can call a function after it completes the 2000ms transition.
Updated fiddle: http://jsfiddle.net/CqR9E/392/
$(window).load(function () {
setTimeout( go(),500);
});
function go(){
$("#man").show("slide", {
direction: "up"
}, 2000, function(){
$( "#man:visible" ).removeAttr( "style" ).fadeOut();
go();
});
}
I have a menu with categories,
when I hover on a category a drop down show up
(I have already delayed the drop down to show up after 600 MS),
I want to know how to delay the hover event on the category too for 600 MS,
What is the best way and easiest way to achieve this using jquery?
jQuery('div.dropdown').hover(function() {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
});
I have made a bootply here http://www.bootply.com/lXioubaMre
You could use a basic CSS transition
.services-shortcut {
transition: all 0s .6s;
}
that runs immediately after a 600ms delay
Example: http://www.bootply.com/xppQzbvQ3P
If you choose to do this effect absolutely in javascript (but I wouldn't do it, just to keep off style from javascript) then apply the active class after a 600ms timeout, e.g.
jQuery('div.dropdown').hover(function() {
var $this = $(this);
setTimeout(function() {
$this.find('.services-shortcut').addClass('active');
}, 600);
$this.find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, ...
If you use this approach then you should also clear the interval onmouseout
You can use hoverIntent jQuery plugin, which triggers functions based on client mouse movement. In your case the script would be simple, you can take a look at this Bootply:
function showMenu(e) {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').show();
};
function hideMenu(e) {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').hide();
};
$("div.dropdown").hoverIntent({
over: showMenu,
out: hideMenu,
sensitivity: 3,
timeout: 800
});
$(".dropdown-menu a").hoverIntent({
over: function(){
$(this).addClass('active')
},
out: function(){
$(this).removeClass('active')
},
sensitivity: 3
});
I would use $.hoverDelay() plugin that does exactly that. It lets you configure the delay(s) for the 'in' and 'out' events like so:
$('div.dropdown').hoverDelay({
delayIn: 200,
delayOut:700,
handlerIn: function($element){
$element.css({backgroundColor: 'red'});
},
handlerOut: function($element){
$element.css({backgroundColor: 'auto'});
}
});
You can simply use jQuery.delay() method :
jQuery('div.dropdown').hover(function() {
alert("Action delayed");
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
}).delay(600);
.dropdown{
background-color:red;
]
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="dropdown">
aaaa
</div>
That will wait for 600ms before executing your action, that's all you need.
Hi I'm trying to do a simple chain animation in jQuery, with a pause (setTimeout) between each frame.
Say each div animates in with a duration of 3500. I would like to control the duration between each opacity fade in animation. Say between the first div and 2nd div the duration is 5 secs, and maybe 10 secs between the 2nd and 3rd frame.
How would you go about this?
http://codepen.io/leongaban/pen/Feroh
Current code
$('#blue').animate({
opacity: '1'
}, 3500, function(){
// Need 5 sec pause here
$('#blue').fadeOut('fast');
$('#orange').animate({
opacity: '1'
}, 3500, function(){
// Need a 10 sec pause here
$('#orange').fadeOut('fast');
$('#green').animate({
opacity: '1' }, 3500);
});
});
That's what delay() and queue() is for:
$('#blue').animate({opacity: '1'}, 3500).delay(5000).queue(function() {
$(this).fadeOut('fast');
$('#orange').animate({opacity: '1'}, 3500).delay(10000).queue(function() {
$(this).fadeOut('fast');
$('#green').animate({opacity: '1'}, 3500);
});
});
FIDDLE
This is exactly what .delay() is for (http://api.jquery.com/delay/). It allows you to write elegant chains of animations for individual elements like this:
$( "#foo" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );
Note that you will still need to use callbacks to start animations for other objects, though.
In your case, this should be it (untested):
$('#blue')
.animate({ opacity: '1' }, 3500)
.delay(5000)
.fadeOut('fast',
function() {
$('#orange')
.animate({ opacity: '1' }, 3500)
.delay()
.fadeOut('fast',
function() {
$('#green')
.animate({ opacity: '1' }, 3500);
});
});
You can use jQuery fadeOut/fadeIn methods with callbacks.
See here for more information.
But essentially is;
$(".myClass").fadeOut(1000, function() {
//fadeOut complete
});
The first argument is length of time (in ms) until it completely fades out. After that duration has passed the callback fires. So you can safely assume that when the callback fires that your required waiting time has completed.
It's the same syntax for fadeIn also, but I suggest reading the link I provided. It'll explain it it greater detail.
I've got this script that I have been working on and I need it to fade in and move up by it's height. If I remove the .animate() it fades in so i'm guessing theres something wrong there.
function showDesc (){
$(".container-box").hover(function(){
$(this).find(".contain-desc").fadeIn('slow').animate({
'bottom':'130px'
}, {duration: 'slow', queue: false;}
},function(){
$(this).find(".contain-desc").fadeOut();
});
}
I do have to use the old fashioned way of onmouseover="" in the html and below is my complete code so far, thanks.
http://jsfiddle.net/silverlight513/KuJkY/
The error is here:
{duration: 'slow', queue: false;}
You have terminated the statement with a semi-colon(;)
Change it to:
{duration: 'slow', queue: false}
EDIT:
There were a couple more errors in your code. I have updated the function:
function showDesc (){
$(".container-box").hover(function(){
$(this).find(".contain-desc").fadeIn('slow').animate({
'bottom':'130px'
}, {duration: 'slow', queue: false});//This was not closed
},function(){
$(this).find(".contain-desc").fadeOut();
});
}