views:

39

answers:

3

Is this the right way to make 2 divs fadeIn together? (contact_close should be infront of contact_box to serve as a close button for contact_box.

EDIT: fixed some divnames.

Javascript

$(document).ready(function(){ 

 $(".button_contact").click(function() { 
    $("#contact_box").fadeIn("slow");
 $(".contact_close").fadeIn("slow");
});

 $(".contact_close").click(function() { 
      $(this).fadeOut("slow"); 
      $("#contact_box").fadeOut("slow"); 
    });

});

CSS

body{
    margin: 0;
    padding: 0;
    text-align: center;
    background-color:#f0f2df;
}

#container{
    border: solid 1px #f0f2df;
    background-color:#f0f2df;
    text-align: left;
    margin: auto;
    width: 939px;
    height: 570px;
    top:41px;
    position:relative;
}
#contact_box{
    display: none;
    background-image:url(../images/bg.png);
    width: 703px;
    height: 379px;
    position:absolute;
    left:236px;
    bottom:34px;

}
.contact_close{
    display:none;
    background-image:url(../images/close.png);
    width:17px;
    height:17px;
    position:absolute;
    right:5px;
    top:135px;
}

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<title>test</title>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/click.js'></script>
</head>

<body>
    <div id="container">
        <div class="button_contact"></div>
        <div id="contact_box">
        <div class="contact_close"></div></div>
</div>
</body>
</html>
+2  A: 

Yes, that's fine.

There are various ways to do many things, but something as simple as this doesn't really require a very technical approach.

Jonathan Sampson
A: 

I didn't analyze your code thoroughly, but it seems more logical to place the close box inside the div, not beside it.

stereofrog
A: 

You can fade them both in the same statement with

$('#contact_box, .contact_close').fadeIn('slow')

This is more efficient because jQuery only starts one fade operation.

sakabako