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?
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.
With jQuery, you can create custom animations.
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").
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With