Jamiex304
Jamiex304

Reputation: 242

Jquery Slide messing up other div's

I have a sight problem with jquery slide at the moment I have atached a code snippet that will show you the problem

Right now when I click the wrapper3head to drop down the wrapper 3 information it push 3 of the pad shapes down

My problem is that the 2 wrappers are now where near the pad but it still pushes them down

I am looking for help to get the 3 pad shapes to stay when I click the wrapper3head

if you run the snippet you will see what I mean just click the choose memory style div

    $(document).ready(function(){
    $("#wrapper3head").click(function(){
    $("#wrapper3").slideToggle("fast");
    });
    });
	
	$(document).ready(function(){
    $("#Informationhead").click(function(){
    $("#Information").slideToggle("fast");
    });
    });
.wrapper {
  position: relative;
  width: 1000px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
}


.wrapper2{
  position: relative;
  width: 652px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
}

.wrapper3head{
  position: relative;
  width: 200px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
  text-align:center;
  float:right;
  margin-right:1%;
}

.wrapper3{
  position: relative;
  width: 185px;
  margin: 0 auto;
  display:none;
  border: 5px groove #8E2B2B;
  text-align:center;
  float:right;
  margin-right:1%;
}

.Informationhead{
  position: relative;
  width: 652px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
  text-align:center;
}

.Information{
  position: relative;
  width: 635px;
  margin: 0 auto;
  display:none;
  border: 5px groove #8E2B2B;
  text-align:center;
}

.back {
  position: relative;
  width: 648px;
  height: 648px;
  z-index: 0;
  background-color: #000;
  border:3.5px ridge white;
  border-radius: 310px;
}

.pad {
  width: 300px;
  height: 300px;
  float: left;
  z-index: 1;
  margin: 10px;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
  filter: alpha(opacity=60);
  opacity: 0.6;
}

.shape1 {
  border-top-left-radius: 300px;
  background-color: green;
  border:2.5px groove white;
  
}

.shape2 {
  float: left;
  border-top-right-radius: 300px;
  background-color: red;
  clear: right;
  border:2.5px groove white;
  position: relative;
}

.shape3 {
  float: left;
  border-bottom-left-radius: 300px;
  background-color: yellow;
  clear: left;
  border:2.5px groove white;
}

.shape4 {
  float: left;
  border-bottom-right-radius: 300px;
  background-color: blue;
  border:2.5px groove white;
}

.Timer {
  position: absolute;
  top: 195px;
  left: 195px;
  width: 250px;
  height: 250px;
  background: #000;
  border-radius: 125px;
  border:2.5px solid White;
  z-index: 10;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>

    <br />
	<center><img src="Media/GroupLogo1.png" alt="Logo" height="200" width="250"></center>
	<br />
	
	<div class="Informationhead"id="Informationhead">Information</div>
	<div class="Information"id="Information">
	<p>Hello</p>
	</div>

	<div class="wrapper">
	<div class="wrapper3head"id="wrapper3head">Choose Your Memory Style</div>
	<br />
	<br />
	<div class="wrapper3"id="wrapper3">
	<p>Do You Want Sound ?</p>
	<input type="checkbox" value="No" style="color: Black;" id="sound">Yes
    <p>Do You want Flashes ?</p>
    <input type="checkbox" value="No" style="color: Black;" id="flash">Yes
    <p>Do You want Text ?</p>
    <input type="checkbox" value="No" style="color: Black;" id="text">Yes
	</div>
	
		<div class="back">
			<div class="pad shape1" data-pad="1">
				<audio preload="auto" class="sound1">
					<source src="Media/sounds/mp3/sounds_01.mp3" type="audio/mpeg"/>
					<source src="Media/sounds/ogg/sounds_01.ogg" type="audio/ogg"/>
				</audio>
			</div>
			<div class="pad shape2" data-pad="2">
				<audio preload="auto" class="sound2">
					<source src="Media/sounds/mp3/sounds_02.mp3"  type="audio/mpeg"/>
					<source src="Media/sounds/ogg/sounds_02.ogg" type="audio/ogg"/>
				</audio>
			</div>
		    <div class="Timer">
			<br />
			<br />
			<br />
			<br />
			<br />
            <center><p><b><i>Time starts when you click start</i></b></p></center> 
			</div>
			
			<div class="pad shape3" data-pad="3">
				<audio preload="auto" class="sound3">
					<source src="Media/sounds/mp3/sounds_03.mp3" type="audio/mpeg"/>
					<source src="Media/sounds/ogg/sounds_03.ogg" type="audio/ogg"/>
				</audio>
			</div>
			<div class="pad shape4" data-pad="4">
				<audio preload="auto" class="sound4">
					<source src="Media/sounds/mp3/sounds_04.mp3" type="audio/mpeg"/>
					<source src="Media/sounds/ogg/sounds_04.ogg" type="audio/ogg"/>
				</audio>
			</div>

		</div>
	</div>

Upvotes: 0

Views: 32

Answers (1)

Fahad Hasan
Fahad Hasan

Reputation: 10506

This is happening because the dropdown has a relative position. You will need to give it an absolute position so that it doesn't affect any other elements on the page once it opens. Adding this CSS to your stylesheet will fix the problem:

.wrapper3 {
     position: absolute;
     right: 0px;
}

Here's a working demo:

$(document).ready(function() {
  $("#wrapper3head").click(function() {
    $("#wrapper3").slideToggle("fast");
  });
});

$(document).ready(function() {
  $("#Informationhead").click(function() {
    $("#Information").slideToggle("fast");
  });
});
.wrapper {
  position: relative;
  width: 1000px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
}
.wrapper2 {
  position: relative;
  width: 652px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
}
.wrapper3head {
  position: relative;
  width: 200px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
  text-align: center;
  float: right;
  margin-right: 1%;
}
.wrapper3 {
  position: absolute;
  right: 0px;
  width: 185px;
  margin: 0 auto;
  display: none;
  border: 5px groove #8E2B2B;
  text-align: center;
  float: right;
  margin-right: 1%;
}
.Informationhead {
  position: relative;
  width: 652px;
  margin: 0 auto;
  border: 5px groove #8E2B2B;
  border-radius: 15px;
  text-align: center;
}
.Information {
  position: relative;
  width: 635px;
  margin: 0 auto;
  display: none;
  border: 5px groove #8E2B2B;
  text-align: center;
}
.back {
  position: relative;
  width: 648px;
  height: 648px;
  z-index: 0;
  background-color: #000;
  border: 3.5px ridge white;
  border-radius: 310px;
}
.pad {
  width: 300px;
  height: 300px;
  float: left;
  z-index: 1;
  margin: 10px;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
  filter: alpha(opacity=60);
  opacity: 0.6;
}
.shape1 {
  border-top-left-radius: 300px;
  background-color: green;
  border: 2.5px groove white;
}
.shape2 {
  float: left;
  border-top-right-radius: 300px;
  background-color: red;
  clear: right;
  border: 2.5px groove white;
  position: relative;
}
.shape3 {
  float: left;
  border-bottom-left-radius: 300px;
  background-color: yellow;
  clear: left;
  border: 2.5px groove white;
}
.shape4 {
  float: left;
  border-bottom-right-radius: 300px;
  background-color: blue;
  border: 2.5px groove white;
}
.Timer {
  position: absolute;
  top: 195px;
  left: 195px;
  width: 250px;
  height: 250px;
  background: #000;
  border-radius: 125px;
  border: 2.5px solid White;
  z-index: 10;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>

  <br />
  <center>
    <img src="Media/GroupLogo1.png" alt="Logo" height="200" width="250">
  </center>
  <br />

  <div class="Informationhead" id="Informationhead">Information</div>
  <div class="Information" id="Information">
    <p>Hello</p>
  </div>

  <div class="wrapper">
    <div class="wrapper3head" id="wrapper3head">Choose Your Memory Style</div>
    <br />
    <br />
    <div class="wrapper3" id="wrapper3">
      <p>Do You Want Sound ?</p>
      <input type="checkbox" value="No" style="color: Black;" id="sound">Yes
      <p>Do You want Flashes ?</p>
      <input type="checkbox" value="No" style="color: Black;" id="flash">Yes
      <p>Do You want Text ?</p>
      <input type="checkbox" value="No" style="color: Black;" id="text">Yes
    </div>

    <div class="back">
      <div class="pad shape1" data-pad="1">
        <audio preload="auto" class="sound1">
          <source src="Media/sounds/mp3/sounds_01.mp3" type="audio/mpeg" />
          <source src="Media/sounds/ogg/sounds_01.ogg" type="audio/ogg" />
        </audio>
      </div>
      <div class="pad shape2" data-pad="2">
        <audio preload="auto" class="sound2">
          <source src="Media/sounds/mp3/sounds_02.mp3" type="audio/mpeg" />
          <source src="Media/sounds/ogg/sounds_02.ogg" type="audio/ogg" />
        </audio>
      </div>
      <div class="Timer">
        <br />
        <br />
        <br />
        <br />
        <br />
        <center>
          <p><b><i>Time starts when you click start</i></b>
          </p>
        </center>
      </div>

      <div class="pad shape3" data-pad="3">
        <audio preload="auto" class="sound3">
          <source src="Media/sounds/mp3/sounds_03.mp3" type="audio/mpeg" />
          <source src="Media/sounds/ogg/sounds_03.ogg" type="audio/ogg" />
        </audio>
      </div>
      <div class="pad shape4" data-pad="4">
        <audio preload="auto" class="sound4">
          <source src="Media/sounds/mp3/sounds_04.mp3" type="audio/mpeg" />
          <source src="Media/sounds/ogg/sounds_04.ogg" type="audio/ogg" />
        </audio>
      </div>

    </div>
  </div>

Upvotes: 1

Related Questions