user1304264
user1304264

Reputation: 1

jQuery Hover Toggling

I'm trying to use this jQuery to activate my css transitions. Also, upon hovering over the div "box", I wanted this to activate the fade in of another div called "box_content".

Any help would be appreciated. Thanks!

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>test</title>
    <style>
        div.box{
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background: #0F0;
            opacity: .3;
            -webkit-transition: all .5s ease-in-out;
            -moz-transition: all .5s ease-in-out;
            transition: all .5s ease-in-out;
        }

        div.box.active{
            opacity: 1;
        }

        div.box_content{
            -webkit-transition: all 1.5s ease-in-out;
            -moz-transition: all 1.5s ease-in-out;
            transition: all 1.5s ease-in-out;
            opacity: 0;
        }

        div.box_content.active {
            opacity: 1;
        }
    </style>

    <script>
        $(document).ready(function() 
            $('div.box').hover(function() {
        $('div.box').toggleClass('active');
        $('div.box_content').toggleClass('active');
        }
    </script>
</head>
<body>
        <div class="box"></div>
        <div class="box_content">Content</div>
</body>

Upvotes: 0

Views: 650

Answers (2)

Adam Cook
Adam Cook

Reputation: 620

You had some syntax errors in your jQuery. If you fix those, it works. http://jsfiddle.net/michaeljimmy/brmF3/

$(document).ready(function() {
    $('div.box').hover(function() {
        $('div.box').toggleClass('active');
        $('div.box_content').toggleClass('active');
    });
});

Upvotes: 1

Dennis Rongo
Dennis Rongo

Reputation: 4611

Here you go. :) You were missing a few curly brackets that was throwing an error.

You can play around with it here:

    $(function() {
        $('div.box').hover(function() {
          $(this).toggleClass('active');
          $('div.box_content').toggleClass('active');
        });
    });

Upvotes: 0

Related Questions