Sort slider items using Show/Hide feature in bxSlider

I am using a bxslider on my website with specific settings:

$('#carousel').bxSlider({
    slideWidth: 146,
    minSlides: 2,
    maxSlides: 6,
    speed:500,
    adaptiveHeight: true,    
    moveSlides:3,
    infiniteLoop : false,
    hideControlOnEnd : true,    
    slideMargin: 10
});

Within this slider, there are various DOM elements structured as such:

<div class="itemClass_XX_YY carouselItem">
  <div class="someClass"><img src="path/to/some/picture.png" /><span>SomeTitle</span></div>
</div>

In the code above, class="item_XX_YY", XX and YY represent categories that define each picture. For example, if animals are in category 1 (XX=1) and bears have an ID of 5 (YY=5), then each bear picture within the slider will be labeled item_1_5.

My goal is to filter items within my bxSlider dynamically. Currently, I achieve this using the following code:

$('.categoryList').click(function() {
    var cat  = $(this).data('category');
    var type = $(this).data('type');
    $('.carouselItem').hide();
    $('.item_'+type+'_'+cat).show();
});

The filtering works correctly, but the bxSlider behaves oddly with hidden elements inside it. The "next" and "prev" buttons seem to count any hidden element as visible (which may not be desired).

However, I want the slider to disregard hidden elements. My question is, how can I filter the elements in my bxSlider without affecting the functionality of the prev/next buttons?


Edit: A fiddle demonstrating the issue is available at the following link:

http://jsfiddle.net/swrf991q/7/

After filtering, the next & previous buttons do not function properly, and the number of slides in the pager remains unchanged.

Answer №1

Spent a significant amount of time searching, only to discover that bxsilder does not support item filtering. My alternative solution was to implement slick slider instead.

If you are adamant about using bxsilder, the process to enable filtering is quite complex:

  • To begin, create a hidden duplicate of all elements within your HTML structure.
  • Initiate the destruction of the slider using the destroySlider function.
  • Subsequently, remove all elements from the bxslider with $('#carousel').html('')
  • Now transfer desired elements from the hidden duplicate to the slider div (applying filters if necessary).
  • Proceed to create a new slider instance.

Instead of completely destroying and recreating the slider, consider utilizing the redrawSlider function, although I have not personally tested this method.

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

Interact with HTML Radio Buttons to Trigger Input Opening

I need to have a message saying "We're sorry..." and a "black box" displayed only when the radio button is set to YES, otherwise keep it hidden. Can I achieve this using JavaScript only, or is there a way to do it with HTML alone? <h3 >Did you ...

Tips for loading a webpage directly to the center instead of the top position

Is there a way to make the page open at a specific div halfway down the page instead of starting from the top? Here is an example: <div id="d1"> <div id="d2"> <div id="d3"> <div id="d4"> <div id="d5"> <div id="d6"> Do ...

How can I retrieve a specific key from a nested array while using ng-repeat to iterate through it

I have successfully created a code snippet that retrieves JSON data and displays it in HTML using AngularJS. <div class="activity" ng-app="stream" ng-controller="streamCtrl"> <ul ng-repeat="x in myData"> <p class="au ...

Utilizing Promises with Chained .then() Functions

I am struggling with simplifying the readability of my code. I have separated it into two main functions, but I am still dealing with nested .then() statements. I am looking for advice on how to structure these functions more effectively. It is important ...

Devising a method to display configurable products as related items along with their customizable options in Magento

I am in the process of creating an e-commerce website using Magento for a client. The issue I am facing is that when I include a configurable product as a related item, it displays the product but without a checkbox. From what I have researched, Magento do ...

Error in Node.js: Using `import` token incorrectly

I am having trouble figuring out what the issue is. Node v5.6.0 NPM v3.10.6 This is the code snippet: function (exports, require, module, __filename, __dirname) { import express from 'express' }; The error message reads: SyntaxError: Une ...

PHP script is not successfully receiving the Ajax post request that is

As a newcomer to the world of php and ajax, I am facing a challenge in passing a variable from jquery to a php page loaded within a modal window. My php script fetches table information for multiple users. Next to each user's name, there is an edit b ...

Compel the browser to launch a fresh tab

I'm currently working on an app that involves uploading files. One issue I'm facing is that the file system pop up doesn't close after the upload, causing a quarter of the screen to be covered while the test keeps running in the background. ...

Several buttons, each requiring to show distinct text

Currently, I am attempting to enhance an existing project that was graciously created for me. I must admit, I am quite new to this, so please be patient with me! In my project, there are 9 buttons, each triggering the display of a different image upon bei ...

Guide on navigating to a specific page with ngx-bootstrap pagination

Is there a way to navigate to a specific page using ngx-bootstrap pagination by entering the page number into an input field? Check out this code snippet: ***Template:*** <div class="row"> <div class="col-xs-12 col-12"> ...

Is there a way to consistently trigger the browser.webRequest.onBeforeRequest event in Mozilla Firefox when it is launched via a link?

Hello knowledgeable individuals. I am unable to solve this issue on my own. Here is the add-on I have created: 1) manifest.json: { "manifest_version": 2, "name": "Example", "version": "1.0", "description": "Example", "permissions": [ "tabs" ...

Creating a Sticky Header and Footer with Responsive Design: Ensuring Content Div Expansion between Them

Greetings. I am working on creating a simple responsive HTML layout as described below: HTML: <div id="header"></div> <div id="content"></div> <div id="footer"></div> CSS: #header{ wi ...

Retrieve the values of elements

Is there a reliable way to retrieve an element's clientWidth and scrollWidth? I've tried using getCssValue, but it doesn't seem to work. $('.grid-header-col .title').getCssValue('scrollWidth') ...

Having trouble loading a React component

I've been working on breaking down modules from a monolithic React project to store them separately in my npm registry. However, I'm encountering issues with exporting and importing them correctly. Previously, I was using the following code: con ...

Changes influencing independent div elements

My goal is to design a front-end screen with images labeled steps 1-4 lined up next to each other. The concept is that when the user hovers over one of these steps, the corresponding image should fade in below them in a separate div. Upon removing the curs ...

Ways to increase the date by one month in this scenario

I am facing an issue with manipulating two date variables. One of the dates is set to last Friday by default, and I am attempting to add a month to this date using the code snippet below. However, it does not produce the desired result. var StartDate = ne ...

The JQuery(document).ready function does not seem to be executing on the webpage, but it works as expected when placed in a

I have encountered a peculiar problem. It's strange to me because I can't figure out the root cause of it, despite trying everything in the Chrome Developer Tools debugger. Here is a snippet of code that works when I run it from a file on my desk ...

Can someone explain why line-height can affect the width in CSS?

Can you explain how the line-height property functions in CSS? I have noticed that when I set the line-height to be equal or less than the font size, it causes layout width issues. You can view an example of this problem on a jsFiddle here. Currently, my ...

Using AJAX in a loop iteration

I am struggling to grasp AJAX and its application for my specific needs. I am required to incorporate ajax calls within a foreach loop in my project. The challenge arises when contemplating the scenario where using PHP calls could result in all actions fir ...

enabling the editing of two input fields by clicking on a button

Looking to make two input fields editable with a button click. Once edited, the data from these fields will be sent to separate columns in a database using ajax. Struggling to find a solution through online search. Any advice is appreciated! ...