Skip navigation
Currently Being Moderated

How do I expand a different div when a button is rolled over?

Aug 15, 2012 9:39 AM

So what i want to do is, when a button is rolled over i want to expand the outer div the button is sitting in not its own div, but the div on the outside of the button wich is a <nav></nav> div.

 

So the structure would look like this in html

 

<nav>

     <a href="#" class="#"><img src="Menu.jpg /></a>

</nav>

 

I have rules governing the img within the <a></a> anchors what i want it to do is with the img is rolled over it changes the height of the nav div.

 

Please help?

 
Replies
  • Currently Being Moderated
    Aug 15, 2012 10:21 AM   in reply to super waffle

    Is the nav div the same size as the image?

     

    If so, you could just use a :hover effect on the div itself in the CSS.

     

    #nav {

    height:100px;

    width:100px;

    }

     

    #nav:hover {

    height:150px;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 11:19 AM   in reply to super waffle

    How comfortable are you with javascript?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 11:53 AM   in reply to super waffle

    OK, here we go, this should be simple enough...

     

    We're going to use a style swapper. Put this in your <head> section...

     

        <script type="text/javascript">

                function enlarge(id)

                {document.getElementById(id).style.height = '100px';}

                function shrink(id)

                {document.getElementById(id).style.height = '80px';}

                function toggle(id)

                {if(document.getElementById(id).style.height == "80px")

                {document.getElementById(id).style.height = "100px";}

                else{document.getElementById(id).style.height = "80px";}}

        </script>

     

    Now what this will do is swap out a height with a new height in your CSS. You can use whatever heights you want, just make sure the large one is right after the enlarge function and the small one is after the shrink function, then it needs to go "small large small" in the toggle function.

     

    Here's an example of the CSS...

     

     

                #div1, #div2, #div3 {

                    position:relative;

                    top:45px;

                    display:block;

                    width:577px;

                    border:1px solid black;

                    padding:10px;

                    border-radius: 0 0 10px 10px;

                    overflow:hidden;

                    height:80px;

                }

                #wrapper {

                    position:relative;

                    margin:auto;

                    width:610px;

                }

     

    That can go in the <head> or in an external sheet, all you really need to know is all of your div tags need to start at the "shrink" setting from the javasscript. You can name your divs anything you like. Just make sure you use id's for your divs (#)  and not classes (.), that won't work with the javascript.

     

    Here's an example of the HTML. This would go in your <body>...

     

    <div id="wrapper">

                <p><a onmouseenter="enlarge('div1'); shrink('div2'); shrink('div3');" onmouseout="shrink('div1');">Services</a></p>

                <p><a onmouseenter="shrink('div1'); enlarge('div2'); shrink('div3');" onmouseout="shrink('div2');">Products</a></p>

                <p><a onmouseenter="shrink('div1'); shrink('div2'); enlarge('div3');" onmouseout="shrink('div3');">Contact Us</a></p>

                <div id="div1">

                  <p>div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                  div1 div1 div1 div1 div1 div1 </p>

                    <p>div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1

                    div1 div1 div1 div1 div1 div1 </p>

                </div>

                <div id="div2">

                  <p>div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                  div2 div2 div2 div2 div2 div2 </p>

                    <p>div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2 </p>

                    <p>div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2

                    div2 div2 div2 div2 div2 div2 </p>

                </div>

                <div id="div3">

                  <p>div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                  div3 div3 div3 div3 div3 div3 </p>

                    <p>div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3

                    div3 div3 div3 div3 div3 div3 </p>

                </div>

            </div>

     

    Right now, all the divs are set to their small setting by the CSS. When you mouse over them, they grow to their large setting because of the onmouseenter="shrink('div1'); shrink('div2'); enlarge('div3');" onmouseout="shrink('div3'); added to the links (Services Proiducts and Contact Us). That onmouseenter can also be added to an <img /> tag and will do the same thing. The important thing to see is that on mouse enter it will enlarge one div and shrink all of the others, this way you don't enlarge a div by moving the mouse onto an image or link and just leave it expanded when you mouse out to another.

     

    That aught to do it, let me know if you have any questions.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 12:27 PM   in reply to super waffle

    Neither. Don't worry about the "getElementById(id)" in the javascript, you don't need to name your divs after anything in the javascript itself.

     

    You can name your divs anything you like, you would just replace ('div1') with ('yourdivname') in the onmouseenter attribute of your link or image that controls the enlarge/shrink action.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 1:17 PM   in reply to super waffle

    LOL, wut?

     

    I think what you want is called a disjointed (I like calling them remote) rollover.

     

    You can make a remote rollover within DW pretty easily.

     

    First, make sure you know the id's and the file names of the images you plan to use.

     

    Then in Design View click the image you want to add a mouse rollover action on (image1).

     

    Click the + in the Behaviors tab and choose Swap Image.

     

    In the menu that pops up, choose the image you want to have the actual change on (image2) from the list.

     

    Click Browse after the Set source to: and choose the file name you want image2 to change to.

     

    Leave both the preload and restore image checked.

     

    Click OK.

     

    The end.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 1:57 PM   in reply to super waffle

    Sorry, I'm not going to be of much use on that without a link to a live version of the page.

     

    If you could upload it to a test folder and post a link to the test page here, I could probably solve the issue pretty quickly.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 7:14 AM   in reply to super waffle

    You are also increasing the height of your menu image on mouse over (:hover) and that increase is pushing the remaining links off the visible part of the div id="menudiv"

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 10:45 AM   in reply to super waffle

    Unfortunately, with the way you're attempting to do it, it might not work.

     

    You could try adding the enlarge onmouseover for the top menu div to the sub links, that way when you are moused over the sub links, they'll keep the div expanded.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 10:51 AM   in reply to super waffle

    You should be trying to add them to the other images, like the menu image itself, then the sub menu items (not the menudiv).

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 11:18 AM   in reply to super waffle

    CSS3 is not standard in any browser. The newest browsers don't implement all of CSS3 yet, and even some of the attributes they do accept, need to be written out 3-4 different ways. The older the browser, the worse it gets, by far.

     

    Opacity needs 2 versions, one for everything but IE and one for IE

     

    img

    {

    opacity:0.4;

    filter:alpha(opacity=40); /* For IE8 and earlier */

    }

     

    I "think" support goes back a ways as long as you use the filter:alpha

     

    Here's an excellent reference page:

     

    http://www.w3schools.com/cssref/css3_browsersupport.asp

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 1:12 PM   in reply to super waffle

    Sorry, with this particular code, no.

     

    It's possible if we were using a class switcher, but right now it's just a style switcher that affects only the height attribute. It would require re-writing the javascript and most of your styles.

     

    On a class switcher all you would do is add in transition css to the classes that it switches.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 6:09 AM   in reply to super waffle

    super waffle wrote:

     

    I have a question for this page do you have Intenet explorer? look at in there its just a complete mess its not recognizing anything my CSS is doing in there why is that?

     

    When I look at the posted link, they are identical between FF 13 and IE 9.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points