ev vk
ev vk

Reputation: 355

hide elements in table with javascript

I have worked to make a table have a behaviour like the following:

table As you can see, when you click in the arrow, the content hidden is displayed, and the other web elements are not displaced up neither down.You can see how it actually behaves in this page.

I tried to replicate the functionallity but I did not get it. When I click in an item that is supossed to hide from view, it is not a smooth transition, what is more , all the page is displaced up or down(not only the item I want to hide).

I created my own table, similar to the above shown. my table

What I want to do is:

1.Make the transition (hide or show) smoother.

2.Avoid moving up or down ALL the elements of the page (refer please to the hyper link I provided before to see what I need).

  1. Hide two or more elements, for instance, in the above image I marked with blue what I want to hide/show.

This is my table code:

<div class="container">
 //I added the style here because I am still testing the table
<table class="table " style="border-left: 1px solid #dddddd;border-right:#dddddd;">
    <tr class="header">
        <td colspan="4">Modulo 1: Introduction</td>
    </tr>
    <tr>
        <td class="curriculum-icon"><i class="icon-play"></i></td>
        <td><a href="http://themes.vibethemes.com/wplms/skins/demo1/unit/introduction-to-software-training/?id=1260">Introduction to Software Training</a><span class="header">x</span></td>
        <td><span class="free">FREE</span> </td>
        <td><span class="time"><i class="fa fa-clock-o"></i> 00:40:00</span></td>
    </tr>
    <tr>
        <td colspan="4" style="padding:15px;background:#f5f5f5;">
            Praesent sit amet lacus imperdiet, semper libero non, convallis lectus. Nunc nisi quam, dignissim ut luctus non, dignissim pellentesque massa. Etiam ac fermentum risus, vitae dictum quam.
        </td>
    </tr>
    <tr class="header">
        <td colspan="4">Modulo 2: Introduction</td>
    </tr>
    <tr>
        <td class="curriculum-icon"><i class="icon-play"></i></td>
        <td><a href="http://themes.vibethemes.com/wplms/skins/demo1/unit/introduction-to-software-training/?id=1260">Introduction asg</a><span class="header">x</span></td>
        <td><span class="free">FREE</span> </td>
        <td><span class="time"><i class="fa fa-clock-o"></i> 00:40:00</span></td>
    </tr>
    <tr>
        <td colspan="4" style="padding:15px;background:#f5f5f5;">
            Praesent sit amet lacus imperdiet, semper libero non, convallis lectus. Nunc nisi quam, dignissim ut luctus non, dignissim pellentesque massa. Etiam ac fermentum risus, vitae dictum quam.
        </td>
    </tr>
</table>

My Javascript:

    $(".header").click(function () {

        $header = $(this);
        //getting the next element
        $content = $header.next();
        //open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
        $content.slideToggle(500, function () {
            //execute this after slideToggle is done
            //change text of header based on visibility of content div
            $header.text(function () {
                //change text based on condition
                //do something 
            });
        });

    });

Thanks!

Upvotes: 0

Views: 92

Answers (1)

Marylyn Lajato
Marylyn Lajato

Reputation: 1171

As given in the boostrap's documentation, There 's a [collapse layout] that you can use for this case.

Bootstrap Reference : https://getbootstrap.com/docs/4.0/components/collapse/

Sample Code Reference:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="accordion" role="tablist" aria-multiselectable="true">
  <div class="card">
    <div class="card-header" role="tab" id="headingOne">
      <h5 class="mb-0">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
         Modulo 1: Introduction
        </a>
      </h5>
    </div>

    <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne">
      <div class="card-block">
        Sample A
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" role="tab" id="headingTwo">
      <h5 class="mb-0">
        <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Modulo 2: Introduction
        </a>
      </h5>
    </div>
    <div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
      <div class="card-block">
        Sample 2.
      </div>
    </div>
  </div>
</div>

Upvotes: 1

Related Questions