Enhance Your Website by Integrating Slick Slider with Bootstrap 4

I am currently facing a significant issue. I am attempting to integrate three div elements into my slider, and all of them maintain a Bootstrap 4 structure. The code looks like this, and it is being generated from another Jquery function where I am inserting information from a Database. This data is then placed within each card.

  //FUNCIONES
        //Create specialist
function CreateSpecialistCard(specialist, showSpecialtyName) {
            let cardHTML = "";
            cardHTML += '<div><div class="col-xs-12 col-lg-3 col-md-3 float-left has_border_grey border_10 px-0 overflow-hidden mr-2 profile-box">'
                 + '<div class="card d-inline"><div class="col-lg-6 col-md-6 bg-light float-left py-2 text-md-left text-center" style="z-index:101;"> ';
            cardHTML += '<h2 class="text-secondary profile-name">' + ((specialist.gender == "F") ? "Dra. " : "Dr. ")
                 + specialist.firstName + " " + specialist.lastName + '</h2>' +
                 '<button class="btn btn-secondary btn-profile btn-sm my-2" data-toggle="modal" data-target="#modalDoctor' + specialist.id + '"'
                 +  '>View Profile' + '</button>';
            cardHTML += '<h3 class="spec-title">' +  specialist.specialtyDesc + '</h3>' + '<h4 class="center-title">' +
                '' + '</h4>'+ '<h5 class="prov-title mb-1">' + specialist.provinces + '</h5>';
             cardHTML += '<p id="reserveAppointment" class=""> RESERVE APPOINTMENT</p>' + 
                (specialist.teleConsultation === true) ? 
                    '<a class="d-inline-block  mr-1" href="/videoConsultation"><img class="bg-purple py-1 px-1" src="/Content/Img/videoconsultation30.png" style="max-width:30px;"  />' +
                    '</a>' : '';
                cardHTML += (specialist.videoConsultation === true) ? 
                    '<a class="d-inline-block mr-1" href="/teleConsultation"><img class="bg-purple-red py-1 px-1" src="/Content/Img/teleconsultation-30.png" style="max-width:30px;" />'  +
                    <'/a>' : '';
                cardHTML += (specialist.inPersonConsultation === true) ? '<a class="d-inline-block  mr-1" href="/scheduleAppointment">' + 
                    '<img class="bg-light-purple py-1 px-1" src="/Content/Img/presencial30.png" style="max-width:30px;"  />' +
                    '</a>' : '';
               cardHTML += '</div>';     
               cardHTML += '  <div class="col-md-6 float-left"  style="z-index:100;">' +
                        '<img class="profile-img img-fluid"  src="/Content/Img/Medicos/CuadroAsistencial/FORMATO-MÉDICOS.jpg" alt="Doctor" />' +
                    '</div>';     
                 
            if (showSpecialtyName != undefined && showSpecialtyName == true) {
                cardHTML += '<br /><span style="font-size:small;" class="colorcard bold">' + specialist.specialtyDesc + '</span>';
            } else {
                cardHTML += '<br />';
            }            
            cardHTML += '</div></div></div>';
            return cardHTML;
}

Below is the section where I create the row that inserts each card using an anonymous function.

   const DisplayFavoriteSpecialists = (carouselRow) => {
                let resultsHTML = "";
                let modalHTML = "";

                resultsHTML += '<div class="preview-carousel">'; // this sets up the carousel class
                for (var i = 0; i < favoriteModelData.length; i++) {
                    let specialistData = speciality_model.specialistsList.filter(j => j.idEspecialista == favoriteModelData[i]);
                    if ( specialistData ) resultsHTML += CreateSpecialistCard(specialistData[0] , false);
                    if( specialistData )
                     var doctorInfo = specialistData[0];  
                     modalHTML += loadModal(doctorInfo, specialistData[0].idSpecialist);
                }
               
                recentModals.html(modalHTML);  
                resultsHTML += '</div>';
                carouselRow.html(resultsHTML);
        }

After creating the cards successfully, which are displaying as intended, I proceed to call the slick slider so that I can group each card as individual items in the slider.

        $('.preview-carousel').slick({
            slidesToShow: 2,
            slidesToScroll: 1
        });

The slick.js library is properly loaded, but unfortunately, it seems to be non-functional. It's worth noting that each card initially generates a div without any classes or IDs to allow easy interpretation of the items within the slider.

Answer №1

Great news, I located it without any issues. Surprisingly, it wasn't as difficult as I initially thought. My mistake was attempting to execute the slick function within a document ready function. By utilizing an on load function instead, everything now functions perfectly.

  $(window).on('load', function() {
        $('.preview-carousel').slick({
            slidesToShow: 2,
            slidesToScroll: 1
        });
    });

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

How can I wrap text in Angular for better readability?

I've created a calendar in my code that displays events for each day. However, some event descriptions are too long and get cut off on the display. Even after attempting to use Word Wrap, I still can't see the full text of these events unless I c ...

Third Party Embedded Video requiring SSL Certificate

I am currently facing an issue where I am trying to embed videos from a website that does not have an SSL certificate. This is causing my own website to appear insecure when the page with the embedded video loads, despite the fact that my website has its ...

Aligning the .left position to make the border of a <div> synchronized

When working on my Jquery program, I encountered an issue with borders not aligning properly within the container. Specifically, in the execution (where the container is represented by a white box), the left border extends beyond the position().left proper ...

Click to switch divs

I am struggling and in need of help. I have been trying to rotate divs on click using jQuery, which was successful until I had two sets of divs that needed to be rotated independently on the same page. When clicking on the arrows to rotate the content in t ...

What is the best way to code an HTML block with jQuery?

Could someone guide me on creating the following using jQuery: <div class="card"> <img src="images/cat6.jpg" alt="Avatar" style="width:100%"> <div class="container"> <h4><b>John Watson</b></h4> ...

Bug Found in AngularJS v1.3.15: Text Color Rendering Glitch on Page Load with WebKit

It appears that the text colors (which should be blue) are not displaying correctly until a user hovers over the text or resizes the window. I attempted to resolve this issue by adjusting the transition property so that it triggers on hover/active states ...

The process of deleting lines from an image using Javascript

If I have an image of a data-table and I want to eliminate all the grid lines (defined as continuous vertical or horizontal pixels), is there a way to achieve this using Javascript's image data manipulation? I envision looping through a 2D array conta ...

Is there a way I can ensure that two elements have identical heights?

Is there a way to ensure that two different elements in HTML are always the same height using CSS? I attempted to achieve this by setting each element to 50vh in the CSS, but it didn't work. codepen: https://codepen.io/ichfickedeinemutterdudummerwich ...

Correct the string based on a character error

When I have text to display in HTML, for example: var htmlStr = "1.first thing %10-15%. 2.second thing %25-44%. 3.third" And I want to display it in a div: $('#div1').html(htmlStr); However, when I display it in a DIV1 in HTML5 on a mobile pho ...

How can grid be used in CSS/HTML to create two collapsible columns that are side-by-side, maintain equal width, and keep their size when expanded?

Hello all, I'm new here and I have a question that I hope I can explain clearly. I am currently working on creating two collapsible "buttons" positioned side by side (each taking up half of the screen width), which expand when clicked to reveal an equ ...

Obtaining the XPath for a data table containing two td elements that can be simultaneously clickable

<div class="dataTables_scrollBody" style="position: relative; overflow: auto; height: 370px; width: 100%; min-height: 0px;"> <table id="offer_create" class="display article-list ranklist_drag table table-bordered dataTable no-footer" aria-describe ...

I am unable to get the Javascript code `window.print()` to function

I tried creating a basic link to print a page on my website using Google Chrome, but for some reason, the link is not working. Upon checking my console log, I noticed an error message that says: Maximum call stack size exceeded Here is the HTML code I us ...

Exploring depths with nested ng-Repeat in Depth First Search

I am dealing with an object that has variable key names, each of which contains nested objects. My goal is to perform a depth-first search (DFS) over this object. For example, consider the following object: object = { "var1" : { "var2 ...

What is the correct way to show a JavaScript response on the screen?

Here is the JavaScript code I used to call the server API: <script type='text/javascript'> call_juvlon_api(apikey, 'getAvailableCredits', '', function(response) { document.getElementById('show').innerHT ...

Looking to add some movement to your website? Learn how to make an image track your mouse pointer in a specific section of your webpage

I'm just starting out with web design and javascript, so please be patient. My goal is to have an image follow the mouse pointer only when it's within a specific section of my website. I've managed to make the image track the mouse cursor ...

Is there a way to extract just the src attribute from an Image tag using PHP?

Similar Question: How can I extract img src, title and alt using php? <img width="200" height="300" src="http://runapvo.apivo.com/files/2011/06/2444-200x300.jpg" class="attachment-medium" alt="2444" title="2444" /> Given the image tag abov ...

What is the best way to link to a CSS file located in a different directory while being in a subdirectory?

For a project I am working on, I am developing a simple streaming site and have organized my files into different folders. These folders include: HTML CSS Shows Within the "Shows" folder, there is a subfolder named "Testshow". I am facing an issue with ...

Steps to generating a new text document and storing it in a communal folder

Currently facing an issue with my application. I have developed a C# application that generates a text file saved in X:\Public\3rd\ASN\. During development, the files are created and saved without any problems. However, when the applica ...

What is the best way to distinguish automatically generated links using JavaScript?

(Hello Dr. Nick) JavaScript is a new area for me and I am currently working on creating a website using asp.net EF JavaScript and other tools... I have created links based on the information stored in my database, and I want the name of the link to appea ...

Changing the Image Source in HTML with the Power of Angular2

Despite my efforts, I'm unable to display the updated image in my HTML file. In my TypeScript file, the imageUrl is updating as expected and I've verified this in the console. However, the HTML file is not reflecting these changes. In my researc ...