Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Colin Marshall
Colin Marshall
32,861 Points

Rotate Image 360 degrees as it fades in

Hey guys,

I have a logo that fades using javascript after the page loads (Example Here). I was wondering how I would go about making the logo make one full rotation(360 degrees) while it fades in, and then have it stop rotating?

This is my code so far just for the fade in:

$header_logo = $('.header__logo');
$header_logo.delay(500).fadeIn(1250);

Thanks!

1 Answer

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

Here it is in css working on hover. You can apply the changes via jQuery for the same effect. Obviously in reverse order (invisible to visible)

<!DOCTYPE html>
<html>
<head>
    <title>Object</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 100px auto;
            -webkit-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            transform: rotate(0deg);
            opacity: 1;
            filter: alpha(opacity=1);
            transition: all 1s;
        }

        #box:hover{
            -webkit-transform: rotate(180deg);
            -ms-transform: rotate(180deg);
            transform: rotate(180deg);
            opacity: 0;
            filter: alpha(opacity=0);
        }
    </style>
</head>
<body>

    <div id="box"></div>

</body>
</html>
LaVaughn Haynes
LaVaughn Haynes
12,397 Points

It might be easier to just add a class like this

<!DOCTYPE html>
<html>
<head>
    <title>Object</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 100px auto;
            -webkit-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            transform: rotate(0deg);
            opacity: 0;
            filter: alpha(opacity=0);
            transition: all 1s;
        }

        #box.flipped{
            -webkit-transform: rotate(180deg);
            -ms-transform: rotate(180deg);
            transform: rotate(180deg);
            opacity: 1;
            filter: alpha(opacity=1);
        }
    </style>
</head>
<body>

    <div id="box"></div>

    <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script>
        $('#box').delay(800).addClass('flipped');
    </script>
</body>
</html>
Colin Marshall
Colin Marshall
32,861 Points

Thanks! Ya I was trying hard to figure out how I would do that since it was activated on hover. The class makes a lot more sense. Hopefully I can take it from here, I'll let you know the results. Thanks again!

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

No problem. The Jekyll site looks good

Colin Marshall
Colin Marshall
32,861 Points

Thanks man! It's still a work in progress, but now it looks a lot better thanks to you!

Check it out: http://colin-marshall.github.io/