Jquery .slideDown() from top only

179 Views Asked by At

I am trying to slide a div down when a parent element is clicked. I am able to get the slide behavior, however, it not only slides from the top, it also expands from the left, so from the top-left corner. I only wish for it to slide from the top.

I have tried with slideDown(), slideToggle(), and even animating the height with animate(), but the behavior is always the same, sliding from the top-left. I suspect is has something to do with bootstrap but that is just a guess.

Here is my jquery:

$('div.card').click(function() {
  $(this).find("div.details-container").toggle(function() {
    $(this).find("div.details-container").slideToggle(2000);
  });
});
tcard-head {
  border-top: 2px solid #f2f2f2;
  padding: 15px 15px 5px 15px;
  background-color: white;
  font-weight: 600;
  color: black;
  z-index: 2;
}

.pio-details {
  margin-top: -2px;
  overflow: hidden;
}

.details-container {
  overflow: hidden;
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>


<div class="card">
  <div class="tcard-head">
    <div class="row">
      <div class="col-xs-7 text-left">
        <div class="avatar"></div>
        <%= user.full_name %>
      </div>
      <div class="col-xs-2">
        <%=  user.qualification %>
      </div>
      <div class="col-xs-3 text-right">
        <%= user.display_status %>
      </div>
    </div>
  </div>
  <div class="row details-container">
    <div class="col-xs-10 col-xs-offset-1 white-bg pio-details">
      <div class="tcard col-xs-12 col-sm-6">Agency: <span><%= user.agency %></span>
      </div>
    </div>
  </div>
</div>

I am trying to slide the .pio-details div. I wrapped it in the .details-container thinking that might help. I didn't.

I am using Rails 5 and Bootstrap-SASS 3.3.7. Any idea why I might be getting this behavior? Thanks.

0

There are 0 best solutions below