Search code examples
jqueryhtmljquery-animatemove

How to either resize a div and move it or slide to hidden div?


I have a layout set up with my links as images for 4 of them 320x320px. They have a opacity change on hover. What i am looking to do now it either on click the box will expand to a pre-determined size with new content if at all possible. If not then navigate to a hidden div on the same page with the new content. Hope this makes sense.

<!DOCTYPE html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/styles.css" rel="stylesheet" type="text/css">
<title>Adam Sackfield's Portfolio</title>

<script src="scripts/jquery-2.0.3.js"></script>

<script type="text/javascript">
            $(document).ready(function() {
                $("nav a").hover(function() {
                    $(this).stop().animate({
                        opacity: 1
                    }, 300);
                    }, function() {
                    $(this).stop().animate({
                        opacity: 0.3
                    }, 300);
                });
            });
</script>

</head>

<body>

<div id="wrapper">
<header>

    <div id="logo">

        <img src="images/logoarrows.jpg">

    </div><!-- Logo Close -->

    <div id="social">

    </div><!-- Social Close -->

</header>

<nav>
    <a href="#" class="yellow"><p class="yelinner">Home</p></a>
    <a href="#" class="pink"><p class="pinkinner">About Me</p></a>
    <a href="#" class="purple"><p class="purpinner">Portfolio</p></a>
    <a href="#" class="green"><p class="greinner">Contact Me</p></a>     
</nav>

<section>

    <article>

    </article>

    <aside>

    </aside>

</section>

<footer>

</footer>

</div><!-- Wrapper Close -->

</body>
</html>

CSS

*           {
              margin: 0;
              padding: 0;
                                    }


#wrapper    {   
                width: 800px;
                margin-left: auto;
                margin-right: auto;
                background-color: #000000;
                                    }

header      {
                width:1000px;
                height: 220px;


                                    }

#wrapper header #logo {
                width: 400px;
                padding-left: 200px;


                                    }

body        {
              background: #111111;
              color: #FFF;
              font-family:’Open Sans’, sans-serif;
              font-weight: 300;
              font-size: 16pt;
                                    }
a           {
              color: #FFF;
              text-decoration: none;
                                    }

nav         {
              width: 800px;
              margin-top: 60px;
              padding-left: 75px;

                                    }

#wrapper nav a  {
              width: 320px;
              line-height: 320px;             
              display: inline-block;
              margin: 4px;                    
              opacity: 0.3;
              text-align: center;

                                }
.yellow     {       background-image: url(../images/tiles/yellow.jpg);
                    background-repeat:no-repeat;
                      }


.purple     {       background-image: url(../images/tiles/purple.jpg);
                    background-repeat:no-repeat;
                                                   }


.pink       {       background-image: url(../images/tiles/pink.jpg);
                    background-repeat:no-repeat;
                    }

.green      {       background-image: url(../images/tiles/green.jpg);
                    background-repeat:no-repeat; }

Solution

  • <style>
    .dropdownstuff {
        width: 100%;
        height: 100%;
        z-index: 10;
        position:absolute;
        left: 0px;
        top: 0px;
        display:none;
    }
    .Showstuff {
        display:block !important; 
    }
    </style>
    <script>
    $("nav a").onClick(function() {
        n = $(this).attr('class');
        $('.dropdownstuff.Showstuff').removeClass('Showstuff');
        $('.dropdownstuff.'+n).addClass('Showstuff'); 
    });
    
    $("a.dropdownhider").onClick(function() {
        $('.dropdownstuff.Showstuff').removeClass('Showstuff');
    });
    </script>
    

    Then you have some divs below or inside your dropdowns:

    <a href="#" class="yellow"><p class="yelinner">Home</p></a>        
    <a href="#" class="pink"><p class="pinkinner">About Me</p></a>
    <a href="#" class="purple"><p class="purpinner">Portfolio</p></a>
    <a href="#" class="green"><p class="greinner">Contact Me</p></a> 
    
    <div class="dropdownstuff yellow"><a href="#" class="dropdownhider">Hide this</a></div>
    <div class="dropdownstuff pink"><a href="#" class="dropdownhider">Hide this</a></div>
    <div class="dropdownstuff purple"><a href="#" class="dropdownhider">Hide this</a></div>
    <div class="dropdownstuff green"><a href="#" class="dropdownhider">Hide this</a></div>
    

    Upon clicking on of your links, it uses it's class to determine which of the divs to unhide.

    Edit: Now the divs should fill the screen. When you click on the links, the div content will appear by having the class. Not sure exactly what you want with animation though.