Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jquery to animate logo in

I have text that I want to be swapped out for a logo once the user scrolls past a certain point. I already have this working

https://jsfiddle.net/ybh22msj/

The issue is that it just swaps the two items. I actually want a nice animation in. Maybe the logo appearing from the top and pushing out the text. I'm not really sure how to achieve this.

JavaScript

$(document).on('scroll', function() {
    if($(window).scrollTop()> 200) {
        $('#logo2').show();
        $('#logo1').hide();
    }
    else {
        $('#logo2').hide();
        $('#logo1').show();
    }
});
like image 226
onTheInternet Avatar asked Jan 09 '23 13:01

onTheInternet


1 Answers

for simple fade you can use

$('#logo2').fadeOut();
$('#logo1').fadeIn();

or

$('#logo2').slideOut();
$('#logo1').slideIn();

for more complex animations you will need to use animate [http://api.jquery.com/animate/] and set the options

options = {123: 456};
$('#logo2').animate(options);
like image 78
DrCord Avatar answered Jan 11 '23 03:01

DrCord