Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate on an image replacement

Hope you can advise I would like to add some simple fade in out of an image replacement which I have hooked into a select menu.ie,

$("#vehicle").change(function(){     var selected = $(this).val();     $("#selectedVehicle").attr('src', '/assets/images/mini/'+selected+'.png'); });  <img id="selectedVehicle" src="/assets/v2/images/select-vehicle.png"> 

any suggestions how I can do it?

like image 397
Lee Avatar asked Apr 30 '10 12:04

Lee


People also ask

How you can use jQuery to animate a flash to the button?

Pure jQuery solution. var flash = function(elements) { var opacity = 100; var color = “255, 255, 20” // has to be in this format since we use rgba var interval = setInterval(function() { opacity -= 3; if (opacity How can use jQuery to animate a flash to the button? var randomNumber = Math. floor(Math.

Is jQuery used for animation?

With jQuery, you can create custom animations.

Can the animate () method be used to animate any CSS property?

The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").

What does an easing do jQuery?

An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing , and one that progresses at a constant pace, called linear .


1 Answers

This will work best if you preload the images.

$("#vehicle").change(function(){     var selected = $(this).val();     var image = $("#selectedVehicle");     image.fadeOut('fast', function () {         image.attr('src', '/assets/images/mini/'+selected+'.png');         image.fadeIn('fast');     }); }); 

This will fade the image out, change the src, then fade it back in. Reference the jQuery docs for more information on the fading functions.

Again, you should preload your images, otherwise it might fade back while still loading.

like image 59
Matt Avatar answered Nov 10 '22 11:11

Matt