Jquery: Delay before triggering Supersized function? - javascript

I have a page that has a lot of animations on it, as well as the Supersized plugin 9large background image carousel). It seems that loading the background image for the Supersized function disrupts my animations a little, making them jerky.
I am wondering if anyone knows of a way to delay the triggering of a function? EG:
jQuery(function($).delay('1000'){
$.supersized({
//Functionality
slideshow:1, //Slideshow on/off
autoplay:1, //Slideshow starts playing automatically
etc...
Ive tried combinations of the above to no effect.
My goal would be to have all my other animations completed before the plugin gets triggered.
Would anyone have any suggestions on how to achieve this? Thanks!

You can delay the execution of a function using setTimeout.
setTimeout( function() {
$.supersized({});
}, 1000);
Not sure how you are animating your page, but If you are using any of the jQuery animation methods you can also try calling your supersized function from a callback. For example:
$('selector').animate({
left: '+=50'
}, 2000, function() {
$.supersized({});
});
This will call your supersized function after the animation completes.

Related

Why is my jQuery transition is glitchy?

I have a jQuery transition with a css overlay that will work fine if the user mouses over for a second or more....however if the user mouses over quickly then the overlay text stays put without the overlay background. Here is my jQuery code:
$(".cascade-t1").hover(function(){
$(".cascade-corner").fadeOut();
$(".overlay-t1").animate({"left": "-300px"}, 300, function(){
$(".cascade-overlay-content").fadeIn(200);
});
}, function(){
$(".cascade-corner").fadeIn();
$(".cascade-overlay-content").fadeOut(200, function(){
$(".overlay-t1").animate({"left": "130px"}, 300);
});
});
Here is the script in action
It looks like the issue is that you don't fadeIn() the .overlay-t1 text until the mouseenter animation is done, and on mouseleave you fadeOut() the text out right away before the animation. When you move your mouse in and out faster than initial the animation the code will fade out the text and then fade it in again (the issue you're seeing).
One possible solution is to slightly alter your bottom (mouseleave) function to resemble your top (mouseenter) function more closely. Something like:
$(".cascade-corner").fadeIn();
$(".overlay-t1").stop(true, true).animate({"left": "130px"}, 300, function () {
$(".cascade-overlay-content").fadeOut(200);
});
The .stop() is there to keep the animation from playing over and over when someone spams the box.
FIDDLE DEMO
Not sure how jquery animate works under the hood but it's possible it's using javascript to animate instead of css transitions. The benefit of css transitions is that it does all of the animation calculations before the animation begins and is hardware accelerated. Javascript is at the mercy of the scheduler at a very high level so it will always be choppy.
Try jquery transit.
http://ricostacruz.com/jquery.transit/

jquery fade in and out a background image in div - with cross fade

Have been attempting to have a background div auto rotate through a series of images. The fades are flashing and not crossing. Thoughts are to use jquery to swap out the image via css and fade the new one in. A nice crossover might be nice. This is fairly light weight - or so it seems and would rather not use a plugin.
Any insight on why were not getting a smoother crossover/transition?
setInterval(delayFunction, 10000);
function delayFunction() {
setTimeout( function(){
$('#homeback').fadeOut('slow');
$('#homeback').css("background-image","url(images/home_02.jpg)").fadeIn('slow');
},5000);
setTimeout( function(){
$('#homeback').fadeOut('slow');
$('#homeback').css("background-image","url(images/home_03.jpg)").fadeIn('slow');
},10000);
setTimeout( function(){
$('#homeback').fadeOut('slow');
$('#homeback').css("background-image","url(images/home_04.jpg)").fadeIn('slow');
},15000);
setTimeout( function(){
$('#homeback').fadeOut('slow');
$('#homeback').css("background-image","url(images/home_01.jpg)").fadeIn('slow');
},20000);
};
If you want a simple example of a rotation check out my jsfiddle: http://jsfiddle.net/3yN8a/2/
The comments are right you need to adjust the background image AFTER the fadeout has completed and you do that by passing a second option that is used as a callback for when its done.
$(selector).fadeout('speed',function(){
//execute your background switch then fade in.
});

jQuery animation only works once or twice?

I'm putting together a site where a client has requested a very specific animation in the quicklink scroller.
I've used jquery animate and jquery fadeIn to complete a glass-shine and glow effect on hover, but when hovered once or twice (partcularly if done in quick succession) it stops happening?
Link: http://clientzone.fifteenten.co.uk/visioncode/html
$('.fadehover').append('<div class="hover"></div>');
$('.fadehover').hover(
function() { $(this).children('div.hover').animate({"left": "+=505px"}, 300);},
function() { $(this).children('div.hover').css({left: "-=" + 505});
});
$('.fadehover a').hover(
function() { $(this).children('div.qlink_glow').fadeIn('fast')},
function() { $(this).children('div.qlink_glow').fadeOut('fast');
});
Any assistance would be hugely appreciated I'm so confused... I've had this happen on other hover effects too
Try .stop(true,true) before .animate, .fadeIn and .fadeOut
This error occurs on your element if you hover in before your last animation finished. A first attempt to me would be trying if it helps to stop the animation before beginning a new one:
$(this).children('div.qlink_glow').stop(true,true).fadeIn('fast');
I'll have to test it, can't say for sure if this will work, just a possibility you could try.

JQuery animation: Is it possible to change speed during the animation?

I want to move a div down a page, and I want it to slow down as it reaches the target.
I tried using call back with recursive func but it doesn’t look smooth:
function MovePanel() {
sidePanel.animate({
"marginTop": newCurrTop
}, moveSpeed, function () {
MovePanel();
});
}
Is it possible to slow down an JQuery animation?
If not what are the alternatives?
Thanks.
The animate method takes a 3rd param called "easing"; learn about it here:
http://api.jquery.com/animate/
You might want to check this out: http://www.learningjquery.com/2009/02/quick-tip-add-easing-to-your-animations
Easing can really bring life to an
effect. Easing controls how an
animation progresses over time by
manipulating its acceleration.

Using jQuery for alternating png transition

Very basic question. I have a very simple web design utilizing a png with transparency, overlaying another base image. The idea here is that it cycles visibility continously, fading in quickly, displaying for a longer interval, fading out quickly, and remaining invisible for an equal longer interval, basically replicating the behavior of an animated GIF from back in the day. The png starts with display set to none.
My problem is jQuery doesn't seem to have a "pause" or "delay" event handler to help here. There are numerous plugins filling the gap, but I'd rather not include one if there's a simple way that I'm missing. That might require falling back on setInterval or setTimeOut, but I'm uncertain of the syntax to do that.
What I want schematically is something like:
--loop start--
$("#pngOverlay").fadeIn(1000);
(5000 delay) // using setTimeout or setInterval if jQuery method unavailable
$("#pngOverlay").fadeOut(1000);
(5000 delay)
--loop repeat--
The following does the behavior once, so I guess if this could be wrapped in a loop it might work, but it doesn't strike me as elegant or the right way.
setTimeout(function() {
$("#pngOverlay").fadeIn(1000);
}, 5000);
setTimeout(function() {
$("#pngOverlay").fadeOut(1000);
}, 10000);
Thanks for any suggestions. I would just use GIFs, but need the transparency for this. (In the old days, we used animated GIFs and we liked them...)
<script language="JavaScript" type="text/javascript">
function showimage(){
$("#pngOverlay").fadeIn(1000);
setTimeout('hideimage()',5000);
}
function hideimage(){
$("#pngOverlay").fadeOut(1000);
setTimeout('showimage()',5000);
}
$(document).ready(function() {
showimage();
});
</script>
Something like this?
setInterval(function()
{
var elm = $('#pngOverlay');
if (elm.is(':hidden'))
elm.fadeIn(1000);
else
elm.fadeOut(1000);
}, 5000);
How about using an animated PNG?
One trick I have seen is to have jQuery carry out an animation for 5000 milliseconds that has no visible effect.
$("#pngOverlay").animate({opacity:1}, 5000);
If the opacity of the item was 1 to start with then it does not have a visible effect but it does pause for 5 seconds.

Categories

Resources