What's the best way to insert div items into a jQuery Slider while ensuring a minimum of 5 elements are displayed and providing a Left-Right slider option to

I have a bunch of div elements on my page, each with the col-sm-3 class from Bootstrap. Currently, I have 6 of these elements arranged in such a way that 4 are on one row and 2 are on the next row, taking up half of that row. Now, I want to display all these elements on a single row within a slider using JQuery, where a minimum of 5 elements will be visible at once, and users can navigate through them using left and right arrow buttons.

After some research, I came across an example called lightSlider in JQuery which seems to fit my requirements: . Specifically, I would like my implementation to resemble the second red example on their website.

However, when I attempted to use the lightSlider class on my elements as per the documentation, no changes were observed on the page.

Below is a snippet of my HTML:

<div class="row whiteBG" id="lightSlider">
        @foreach (var item in Model)
        {
            <div class="col-sm-3 align-centre">
                <img src="@item.OutputImage" alt="@item.Image" />

                <a href="@Url.Action("Products", "Home", new { id = item.Id, categoryName = item.Name })">
                    <div class="blend-box-top category-head" style="background: #0197BA url(@item.OutputImage) no-repeat 50% 0%;">
                        <div class="item-container">
                            <div class="desc-plus">
                                <p>@item.Name</p>
                                <p>+</p>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        }
    </div>

In addition to this, I included the following script just before the closing body tag:

<script type="text/javascript>
  $(document).ready(function() {
    $("#lightSlider").lightSlider(); 
  });
</script>

I am utilizing Visual Studio for development, and by default, JQuery is loaded at the bottom of the _Layout.cshtml file along with other necessary scripts for my project.

Answer ā„–1

<div class="col-sm-3 align-center">

Modify the class from 3 to 2 in order to accommodate 5.

Answer ā„–2

My first encounter with JQuery was a learning experience as I faced an issue while working on a slider example. Initially, I made the mistake of including all classes from the HTML shown in Chrome Developer Tools for a specific slider demonstration at this link: . However, this led to errors as I should have only used one class, which automatically added additional classes to my HTML.

To resolve the issue, I integrated the lightslider.js, lightslider.css, and controls.png files from this repository: https://github.com/sachinchoolur/lightslider/tree/master/src into my project.

The key step involved inserting the following script before the closing body tag in my HTML page:

    $(document).ready(function () {
        window.prettyPrint && prettyPrint()

        $('#content-slider').lightSlider({
            keyPress: false,
            item: 5,
            loop: true,
            onSliderLoad: function () {
                $('#content-slider').removeClass('cS-hidden');
            }
        });

    });
</script>

I customized the script slightly to display 5 items initially by modifying the 'item' attribute.

A crucial point to note is that this script must follow the JQuery call script to avoid any issues. It took me some time to identify this issue.

In the 'lightslider.css' file, I had to adjust the filePath to ensure proper inclusion of the image for the left-right arrows, under the '.lSAction > a' class. I located my image in the Images folder and updated the attribute as follows:

background-image: url('Images/controls.png');

This snippet illustrates how I structured my HTML code:

I want to highlight that I only incorporated one class in my HTML list: ul<id="content-slider">, which facilitated the addition of other required elements for the lightSlider, creating the slider example seen here:

<div class="row whiteBG">

        <ul id="content-slider" >

            @foreach (var item in Model)
            {
                <li class="col-sm-4 align-centre">
                    <a href="@Url.Action("Products", "Home", new { id = item.Id, categoryName = item.Name })">

                        <img src="@item.OutputImage" alt="@item.Image" />

                        <div class="blend-box-top category-head" style="background: #0197BA url(@item.OutputImage) no-repeat 50% 0%;">
                            <div class="item-container">

                                <div class="desc-plus">
                                    <p>@item.Name</p>
                                    <p>+</p>
                                </div>
                            </div>
                        </div>

                    </a>
                </li>
            }

        </ul>

    </div>

I share this experience so that others facing similar challenges can benefit from it. :)

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

Communication Between Directives in AngularJS

Recently, I've been working on a custom filter directive in Angular: app.directive('filter', function(){ return { restrict: 'E', transclude: true, scope: { callFunc: '&' }, template: ...

Retrieve information from a button in an HTML file and pass it to an aspx webpage

Here's what I have so far: The Aspx file contains a DataList and SQL DataSource setup that pulls data from the TestDB. <asp:DataList ID="DataList1" runat="server" DataKeyField="AppId" DataSourceID="TestDB" RepeatColumns="1"> <ItemTempla ...

TSDX incorporates Rollup under the hood to bundle CSS Modules, even though they are not referenced

I have recently developed a React library with TSDX and you can find it here: https://github.com/deadcoder0904/react-typical This library utilizes CSS Modules and applies styles to the React components. Although the bundle successfully generates a CSS fi ...

JavaScript prototypal inheritance concept

During my free time, I like to dabble in JavaScript, but Iā€™m currently struggling with this particular topic. var person = new Person("Bob", "Smith", 52); var teacher = new Teacher("Adam", "Greff", 209); function Humans(firstName, lastName) { this. ...

Updating the color of text when clicking on a link using javascript

I am facing an issue where I cannot seem to change the text color using JavaScript. The functionality to show and hide div tags is working perfectly, but changing the color seems to be a challenge. It's worth noting that there are no styles defined fo ...

Controlling visibility of controls in .NET

New to .NET and looking for help. I have a webpage with several sections on it. I'd like to create another page that includes hyperlinks to link to the main page and its sections. My goal is to make all sections visible when the user clicks on the m ...

Issue encountered when attempting to activate a Vue function in order to update a specific component's field

Let me preface this by saying that I am new to Vue.js and still learning the ropes. Here's what I'm trying to achieve: I have a label and a button. The behavior I want is that when the label is not visible, the button should display "Show Label" ...

Change the button's background color gradually when hovered over using CSS

Attempting to create a button that transitions its background color from blue to white and the font color from white to blue. I've reviewed similar posts for guidance. Here is the fiddle showcasing my work: http://jsfiddle.net/t533wbuy/1/ I used thi ...

What is the method for setting a fixed size for a Bootstrap container?

Bootstrap 4 is the framework I am currently using. Below is the HTML code I have written: <div class="sprite container d-inline-block bg-info rounded p-1"> <span class="sprite-span-level">Top-right text over image</span> <img cl ...

The event bus I'm using isn't functioning properly within the axios interceptor, yet it operates smoothly in all my Vue components

Currently, I am utilizing VueJs and mitt for the eventBus. The mitt is globally loaded and functioning correctly as shown below: main.js const emitter = mitt(); const app = createApp(App) app.config.globalProperties.emitter = emitter I am able to call t ...

Curious as to why JavaScript restricts the use of two variables entering at the same time

Currently, I am tackling an Ajax-php livesearch programming challenge. I am facing an issue where JavaScript is unable to receive the values of 2 parameters that I want to input in HTML input boxes. Any idea why this might be happening? This is my HTML co ...

The beforeEach hook in Mocha.js does not support the bail(false) functionality

Whenever I attempt to initiate my mocha test with the instruction bail(false), I am looking to ensure that the tests do not halt even if an error is encountered in a beforeEach hook. Despite setting this configuration, it seems like it's not working ...

Challenges with JavaScript calculations on dynamic HTML forms

Currently, I am immersed in a project focused on creating invoices. My progress so far involves a dynamic form where users can add and remove rows (as shown in the snippet below). I'm encountering an issue with my JavaScript and I could use some ass ...

Beginner coding exercises to master JavaScript

With a proficiency in CSS, HTML, and some knowledge of Jquery and PHP, I aspire to become a Front End Web Developer. However, my lack of understanding in Javascript is holding me back. I acquired my current skillset by rapidly learning over 9 months while ...

Searching for Distinct Users Using Mongoose

Situation Within a MongoDB database, there exists a collection containing mail documents. Each of these documents contains fields for both the receiver and sender. Objective My goal is to fetch a single mail from each unique sender. This means I do no ...

Retrieve values of data attributes and HTML elements into an array

I have a scenario where I have HTML with specific tags containing data-id values and inner HTML values, and I need to extract them into an array. Is there a way to achieve this using either Jquery or Javascript? <li class="dual-listbox__item" data-id= ...

Material-UI Masonry: Eliminate excess spacing on the right side

When utilizing Material-UI, I encountered an issue where the width of the Masonry Component does not completely fill the width of its parent container. The empty space left has a width exactly equal to the spacing between elements, which is understandable ...

Deactivate the Aloha Editor's sidebar

I am struggling to disable the sidebar on the Aloha Editor. I have tried implementing the code below, but it doesn't seem to work for me: Aloha.settings = { sidebar: { disabled: true } }; When I add this code after calling aloha(), nothing changes ...

Differences in browser behavior can cause varying outcomes in the Web API URL

I am currently utilizing jQuery to make Web API calls on my website. Surprisingly, it works perfectly fine when tested in Chrome However, testing it in IE 11 results in a frustrating 404 error An observation I've made is that IE 11 includes the s ...

Accessing an array beyond its callback scope

Currently, I am working on creating an array of objects with different key values by utilizing basic web scraping techniques in NodeJS. One challenge I am facing is accessing the 'built' Array outside of its parent function, which you can find he ...