``Slide your way through Bootstrap tabs with the smooth Slick slider

I have implemented two sliders within the Bootstrap Tabs component. The sliders are functioning properly for the active tab but encounter issues when switching tabs. You can view the problem here: https://codepen.io/cray_code/pen/PxwdvQ

Is there a solution to prevent this behavior?

Below is the HTML code:

<ul class="nav nav-tabs" id="myTab" role="tablist">
    <li class="nav-item"><a class="nav-link active" id="games-tab" data-toggle="tab" href="#games" role="tab" aria-controls="games" aria-selected="true">Games</a></li>
    <li class="nav-item"><a class="nav-link " id="movies-tab" data-toggle="tab" href="#movies" role="tab" aria-controls="movies" aria-selected="false">Movies</a></li>
</ul>

<div class="tab-content">
    <div class="tab-pane active" id="games" role="tabpanel" aria-labelledby="games-tab">

        <div class="slider-games">
            <div>
                <h1>Headline</h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            </div>
        </div>

    </div>
    <div class="tab-pane " id="movies" role="tabpanel" aria-labelledby="movies-tab">
        <div class="slider-movies">
            <div>
                <h1>Headline</h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
            </div>
            <div>
                <h1>Headline</h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
            </div>
        </div>
    </div>
</div>
    

And here's the JavaScript code:

$('.slider-games').slick({
    dots: false,
    arrows: true,
    slidesToShow: 2,
});

$('.slider-movies').slick({
    dots: false,
    arrows: true,
    slidesToShow: 2,
});

Answer №1

Here's the solution I discovered at this GitHub link:

You can use the code below to fix content width inside hidden tabs:

/* Correcting content width in hidden tabs for bootstrap */
.tab-content > .tab-pane,
.pill-content > .pill-pane {
    display: block;     /* Revert display:none          */
    height: 0;          /* Invisible with 0 height */  
    overflow-y: hidden; /* No vertical scroll                */
}
.tab-content > .active,
.pill-content > .active {
    height: auto;       /* Set height based on content   */
} /* End of bootstrap correction */

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Jquery to show element when <select> is updated

I've been struggling to make this work due to my limited jquery/js skills. My goal is to have a different message displayed for each option selected from the dropdown menu for further information. <label class="checklabel">Is it possible to re ...

Please ensure you have selected at least one item before submitting the form

I have been working on validating a form using a combination of bootstrap and angularjs. The form includes two groups of checkboxes that need to be validated. It is required for the user to select at least one checkbox from each group in order for the Subm ...

Combining broken down values within a loop

https://i.sstatic.net/PI3NI.png Take a look at this image, then review the code I've provided: function addNumbers() { var inputList = document.getElementById("listInput").value.split(" "); for(i = 0; i <= inputList.length; i+=1) { ...

Access within the identical window (PHP file) as opposed to an Iframe

I am currently working with a PHP file that retrieves data from my database. <?php $cdb = new PDO('mysql:dbname=xxx;host=localhost', 'xxx', 'xxx'); foreach ($cdb->query("SELECT * FROM images ORDER BY posted DESC LIMIT ...

Passing state from React.JS to a link results in an undefined props.location.state

I am facing an issue with passing state to the Link component. When trying to access the state using props.location.satate, it comes up as undefined. Even after attempting to send the state through the to attribute using both pathname and state, it remains ...

What is the best approach to managing the JSON data extracted from a form composed of tabular div elements?

I am dealing with a form that consists of data organized in divs within a table-like layout. Each row represents a record, but when I retrieve the values using serializeArray, I'm having trouble distinguishing between each row. Below is an example of ...

Show a hidden div element when selecting an option from a dropdown menu

A task at hand requires the creation of a function that will dynamically display certain parts of a form based on user selection. For instance, if 'Pizza' is chosen, then div #section2 containing questions related to pizza should be revealed. Pr ...

Arranging an array of JavaScript objects based on a sub-array's property/value

When data is returned from a server, the structure may not always be in our control. For example... var data = { "TrackingResults": [ { "Name": "Pack One", "Products": { "Product": [ ...

Is there an issue with .addClass not working on imported HTML from .load in jQuery?

I have set up a navigation bar that hides when the user scrolls down and reappears when they scroll up. I want to keep the navbar code in a separate HTML file for easier editing. .load In the index.html file, the navbar code is included like this: <di ...

Tips for customizing fonts in react-pdf

I am having difficulty in changing fonts within react-pdf. // Register Font Font.register({ family: "Roboto", src: "https://cdnjs.cloudflare.com/ajax/libs/ink/3.1.10/fonts/Roboto/roboto-light-webfont.ttf" }); The default f ...

Tips for choosing a visible element in Protractor while using AngularJS

I am working on a Single Page Application that contains multiple divs with the same class. My goal is to have protractor identify the visible div and then click on it. However, I keep encountering the error Failed: element not visible, which leads me to be ...

Controlling a complex IF statement with jQuery

Currently, I have an if statement with over 100 different conditions. Right now, I am using a structure similar to this... $('select').on("change",function(){ if( $(this).val() === 'tennis' ) { $('.sport').val( ...

What is the best location in my redux store to store my socket connection?

As a beginner in the world of Redux, I've been using slices and redux-thunks to manage my redux store. However, I've come to realize that storing my socket connection in the state is not ideal. This connection is critical across multiple componen ...

Is it possible to transfer .NET backend functions to a frontend framework like React or Vue for client-side execution?

For instance, imagine a scenario where there is a login page requiring a username and password to meet specific criteria for validation: the username must contain a capital 'A' and the password should be exactly 8 characters long. The challenge l ...

Vows: proceed to the subsequent error handling process

Can you explain how to properly call the next error function using promise chaining? I initially believed that placing a return statement within the error function would automatically trigger the next error function. //This code is executed in a contr ...

Is it possible to dynamically create input fields in AngularJS by clicking a button?

I'm currently working on a project that involves adding an input field and a button each time a user clicks on the button. Is there a way to retrieve the text from the input field when the new button, which is displayed alongside the input field, is ...

Different ways to verify if a Checkbox is selected within a table

As a newcomer to reactjs, I have a component that renders two tables with different data using the same component and passing data through props. Each table has checkboxes for selection. If a user selects items from both tables, I want to detect if they ha ...

Accordion-inspired animation implemented on an Angular component using a selection of different templates

Currently, I am developing a production app with a card-style layout. All filters (such as date pickers) and visualizers (like tables and charts) are enclosed within a "Card" component. Additionally, there are two child components that inherit from this cl ...

Transmitting HTML content to the browser from the client using Node.js

Quoted from: Book - "Getting MEAN with Mongo, Express.." When it comes to responding to requests in your application by sending HTML to the browser, Express simplifies this process compared to native Node.js. With support for various templating e ...

The issue arises when using IE8/9 with $.get and .html() functions, as the retrieved data

Below is a snippet of JavaScript code that I am currently working with: $(".refresh").on("click touch", function () { $.get($("a.suggest-date").attr('href') + '#suggestedDate', null, function (result) { console.log(result); ...