Php

Dynamically Create Bootstrap Tabs With Carousel Using PHP and jQuery

In this tutorial, we will learn how to create tabs based carousel. We are using bootstrap tabs and carousel functionality. We got a situation where a web page has 20 tabs in a series then it is very difficult to manage UI.

it will show a horizontal bar if the length of the tabs exceeds div width. The best and most excellent way is to create a carousel on tabs and provide end-user features to navigate tabs.

Also check out other tutorials on bootstrap tabs and pills,

How to Create Dynamic Tabs with Bootstrap Using Carousel

Step 1: Initialize the carousel library.

Related Post
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="/carousel.js"></script>

Step 2: we will define the tabs array in PHP, which will contain the tab name.

$tabs = array('tab1', 'tab2', 'tab3', 'tab4','tab5', 'tab6');

Step 3: Finally, we will define the Carousel HTML structure with PHP.

<div id="itemdCarousel" class="nav-bar">
 <div style="margin-left: 68px ! important; width: 77%; height: 10px;margin-bottom:22px" class="navbar-inner">
  <div class="carousel slide" id="myCarousel"> 
   <div id="myCarousel" class="carousel slide">  
    <!-- Carousel items -->  
    <div class="carousel-inner">
     <ul class="carosel-ul nav">
      <div class="item active">
       <?php $i=0;
       $tabs = array('tab1', 'tab2', 'tab3', 'tab4','tab5');
       foreach($tabs as $tab):
        echo "<li style='float:left;margin:0px 20px;' class='fc-button fc-button-today fc-state-default fc-corner-left fc-corner-right'>".$tab."</li>";
        $i++;
        if($i%3 == 0 &amp;&amp; count($tabs) !=$i ):
         echo '</div><div class="item">';
        endif;
       endforeach;
       
       ?>
        
      </div>
     </ul>
    </div>
   </div>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left nav-link" id="prev" style="display:none" href="#myCarousel" data-slide="prev">‹</a> 
  <?php if(count($tabs) > 5) :?>
 <a class="carousel-control right nav-link" id="next" href="#myCarousel" style="" data-slide="next">›</a>
  <?php endif;?>
  <input type="hidden" name="itemcount" id="itemcount" value="<?php echo count($existRec);?>">
</div>
</div>

Step 4: Finally java script Carousel method to show and hide nav bar.

jQuery('.carousel').carousel({  
  pause: true,
  interval: false
});

jQuery(".nav-link").live('click', function()
  {
 if(jQuery(this).hasClass('right')) {
    var tot = parseInt(jQuery('#itemcount').val());
    jQuery('#itemcount').val(tot-5);
    jQuery('#prev').show();
 }
});

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

4 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

10 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

10 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

10 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

11 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

11 months ago

Categories