Problem with Owl Carousel width on various devices

I am encountering a problem with an Owl Carousel (v2.3.4) that is causing the carousel to randomly resize and the images to disappear on certain devices. The issue seems to occur when interacting with another Owl Carousel I have loaded on the page. Despite trying various solutions such as adding a separate wrapper for width control, using different initialization methods, and delaying the initialization process, the problem persists.

The problematic Owl Carousel can be found in the Green block on the development page:

Since I only want this slider to appear on specific devices, I am currently utilizing the following Javascript:

$(function() {

if ($(window).width() < 768) {

    startCarousel();

  } else {

    $('.mob-carousel').addClass('off');

  }

  $(window).on('resize', function() {

    if ($(window).width() < 768) {

      startCarousel();

    } else {

      stopCarousel();

  }

});

function startCarousel() {
  $('.mob-carousel').owlCarousel({
    loop: true,
    margin: 0,
    nav: false,
    dots: false,
    items: 1,
    mouseDrag: true,
    touchDrag: true,
    navText: ["<img src='" + get_template_directory_uri + "/assets/images/right.svg'>", "<img src='" + get_template_directory_uri + "/assets/images/swipe-left.svg'>"],
  });
}

function stopCarousel() {
    var owl = $('.mob-carousel');
    owl.trigger('destroy.owl.carousel');
    owl.addClass('off');
}

Answer №1

When using owl-carousel, include the parameter "autoWidth: true" to automatically set the width of the items.

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

Is there a way to access the history of Vue routers?

I am looking for a way to determine if the Vue router has additional entries in its history that can be navigated back to. This information is crucial for deciding whether or not to execute the exit app function. The app should only navigate back to prev ...

Each time the page is refreshed, the most recent form data submitted is continually appended to an array

I have implemented a post request to add input data from a form. The entered data is stored in an array variable burg and then displayed on my index.handlebars view. Everything works as intended, but when the page is refreshed without any input in the form ...

When Vue.js is compiled, it removes a script tag

I'm currently learning Vue.js and encountering an issue that I can't seem to resolve. My project is utilizing Vue CLI 3, and within my code I am inserting a custom tag (not a component) in my template with a script tag inside it. <ra type="ou ...

What is the process for converting a URL or HTML document to a PDF using the html2pdf JavaScript library?

I am working on creating a button that utilizes the html2pdf library to convert an HTML page into a PDF. Instead of selecting an element with query selector or getElementById, I would like to pass a URL because the page I want to convert is not the same as ...

Using jQuery, identify when any of the elements within every function are missing

In my JavaScript file, I have the following code snippet: var aryYears= []; $(".year").each(function(){ aryYears.push($(this).val()); }) This allows me to pass an array of years as a parameter in the saveChanges function. I want to make ...

React typescript is handling various promise response types, causing strange behavior in type-checking

I recently started utilizing the and I seem to be encountering a perplexing issue. If further context is needed, please let me know and I will provide it. All the necessary functions and types are mentioned below my explanatory paragraphs. Your assistance ...

Is there a way to determine the desired width of an element using jQuery prior to rendering it?

I am currently facing an issue with an element that has not yet been added to the body. Despite having all the necessary classes for a specific box model, I am unable to determine its width before it is appended. When inspecting the element using Firebug, ...

Why does this asynchronous function initially return nothing, only to suddenly return all results on subsequent tries?

My current task involves inserting data into my database within a map loop. To ensure that the loop completes before proceeding, I am utilizing an async function to store all results in the variable "practicasAgregadas." This is how I invoke the function: ...

jQuery import children into output

When inserting a div every nth-child and later calling the children of the parent, the jQuery inserted elements do not appear in this new list. How can I retrieve the inserted elements as well? Apologies if this is confusing. If it's easier to under ...

Convert a linear gradient into an object

Can someone help me convert the linear-gradient value into an object with keys and values? Here is the initial value: linear-gradient(10deg,#111,rgba(111,111,11,0.4),rgba(255,255,25,0.1)) I would like it to be structured like this: linear-gradient: { ...

Is it possible to install a Chrome extension specifically for YouTube on Google Chrome?

Hey, I'm trying to eliminate thumbnail images from YouTube. The code I am currently using is: while (true) { $("ytd-thumbnail").remove() } As of now, when I input this code in the console, it successfully removes all thumbnail images. However, I ...

Presenting a fully equipped GLTF model prior to incorporating it into the environment

I've been experimenting with different methods to accomplish this task: I'm looking to load a model and then have the function return it. var loader = new THREE.GLTFLoader(); loader.crossOrigin = true; var loadedModel = loader.load('model. ...

Choosing a single radio button value within a nested ng-repeat loop in AngularJS

Help needed with selecting only one radio button value in nested ng-repeat. Please review the source code and suggest any potential mistakes. <form ng-submit="save()"> <div ng-repeat="x in surveyLst"> <div class="row"> < ...

Transform your scene into a stunning 3D texture using THREE.js's 3D Render Targets feature

After exploring the THREE.js example available here, I am curious about how to avoid scenes rendered as textures from appearing 'flattened'. Essentially, I want to maintain the depth illusion within the scene when using a WebGLRenderTarget. I ha ...

Create a visually engaging book reader with the power of jQuery and images

For hours, I've been attempting to develop an online Comic Book reader to load my images. Everything is functioning correctly, except for a counter using an increment method that just won't work - reducing the increments breaks the function. Is ...

What is the best way to test the robustness of ajaxterm(J) JavaScript's heartbeat functionality

Currently, my setup involves utilizing AjaxtermJ (a Java version of Ajaxterm). The Ajaxterm client-side includes a javascript function that consistently sends heartbeats to the server every second, regardless of user interaction. In order to optimize the ...

Vue select is causing the selected choice of another selector to be influenced

Currently, I am facing an issue with a table displaying a specific Nova resource. The problem lies in the selectors within each row of the table - when one selector is changed, all other selectors automatically mirror that change. This behavior seems to be ...

Strategies for organizing and handling npm packages within my codebase

Recently, I decided to create a discord bot and used npm for the first time. After setting up my package file and installing discord.js, I now find myself with 3000 files that could be synced to my repository. It seems like an overwhelming situation, and I ...

Ensuring Flexbox items are aligned vertically without creating any mysterious empty spaces between them

I'm encountering an issue with Flexbox's flex-wrap: wrap that appears to be causing additional white space below the div. This is how my setup looks (with class names for clarity): <div class="viewheight-background"> <div class="h ...

Are MobX Observables interconnected with RxJS ones in any way?

Is the usage of RxJs observables in Angular comparable to that in React and MobX? I'm struggling to find information on this topic. ...