I am making a website, and it allows users to change view options. I use jQuery to smooth animations for font changing. It fades the whole page out and back in again with the new fonts.
The fade out animation is fine, but when it fades back in, there's no fade. It just pops up, no animation.
The problematic jQuery is in http://xsznix.my3gb.com/options.php.
The code I have so far is this:
$('#font-classic').click(function(){ $(document.body).animate({opacity: '0%'},{duration: 1000, complete: function(){ // font changing code here $(document.body).animate({opacity: '100%'}, 1000); }}); });
jQuery Effect fadeTo() MethodThe fadeTo() method gradually changes the opacity, for selected elements, to a specified opacity (fading effect).
As theIV said you can use the css method, but as an alternative you can use animate: $('#my_element'). animate({ opacity: 0.5 }, 100); this will animate the opacity of you div (and its contents) to 0.5 (from whatever it was to begin with) in 100 milliseconds.
With jQuery, you can create custom animations.
The . fadeTo() method animates the opacity of the matched elements. It is similar to the . fadeIn() method but that method unhides the element and always fades to 100% opacity.
jQuery's .animate()
takes values from 0
to 1
.
$(document.body).animate({opacity: 0}, 1000); $(document.body).animate({opacity: 1}, 1000);
I'm sure that .animate()
must call .parseFloat()
(or something) on the values you're passing, which would make your 0%
into 0
(which is correct), but your 100%
into 100
, which would be incorrect.
Why not use jQuery
's built-in functions fadeIn
and fadeOut
?
$('#font-classic').click(function(){ $('body').fadeOut('normal', function(){ $('body').fadeIn(); }}); });
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