Adjusting and resetting the slider sizes

Are you an end developer facing issues with sliders in tabs? Your sliders appear to be working, but when switching to the second slider they disappear. The width and height of the slider seem to get lost. Resizing the site using responsive tools in Firefox brings back the width and height. Despite trying resizeFix() and reInit(), nothing seems to work.

Can anyone offer some assistance?

HTML Snippet

<ul id="tabs-wrapper" class="nav nav-tabs" data-tabs="tabs">
  <li id="tabs-button" class="active"><a href="#home" data-toggle="tab">Projects</a></li>
  <li id="tabs-button"><a href="#profile" data-toggle="tab">Shots</a></li>
</ul>
</div>
<!-- Tab panes -->
<div class="tab-content">
    <!-- First slider -->
  <div class="tab-pane fade in active" id="home">
      <div class="device">
                          <div class="arrows">
                          <a class="arrow-left al1" href="#"></a> 
                          <a class="arrow-right ar1" href="#"></a>
                           </div>
                          <div class="swiper-container s1">
                          <div class="swiper-wrapper" style="width:100%; height:100%;">
                          <div class="swiper-slide">
                              <div class="content-slide">
                                <h3 class="title">Slide with HTML</h3>
                                <a href="#" class="button site">website</a>  
                              </div>      
                              <img class="img-work" src="images/drop1.jpg">
                              </div>
                          <div class="swiper-slide">
                              <div class="content-slide">
                                <h3 class="title">Slide with HTML</h3>
                                <a href="#" class="button site">website</a>  
                              </div>      
                              <img class="img-work" src="images/nu.jpg">
                              </div>      
                          </div>
                          </div>
                          <div class="pagination p1"></div>
                        </div>
    </div>
    <!-- Second slider -->
  <div class="tab-pane fade" id="profile">
    <div class="device">
                          <div class="arrows">
                          <a class="arrow-left al2" href="#"></a> 
                          <a class="arrow-right ar2" href="#"></a>
                           </div>
                          <div class="swiper-container s2">
                          <div class="swiper-wrapper" style="width:100%; height:100%;">
                          <div class="swiper-slide">
                              <div class="content-slide">
                                <h3 class="title">Slide with HTML</h3>
                                <a href="#" class="button site">website</a>  
                              </div>      
                              <img class="img-work" src="images/drop1.jpg">
                              </div>
                          <div class="swiper-slide">
                              <div class="content-slide">
                                <h3 class="title">Slide with HTML</h3>
                                <a href="#" class="button site">website</a>  
                              </div>      
                              <img class="img-work" src="images/nu.jpg">
                              </div>      
                          </div>
                          </div>
                          <div class="pagination p2"></div>
                        </div>
    </div>

CSS Snippet

.swiper-container {  
  width: auto;
  height: auto;
  cursor: default !important;
  min-height: 729px !important;
}

Javascript Code

<script>  
   var Swiper1 = new Swiper('.s1',{
    pagination: '.p1',
    loop:true,
    grabCursor: true,
    paginationClickable: true
  })
  $('.al1').on('click', function(e){
    e.preventDefault()
    Swiper1.swipePrev()
  })
  $('.ar1').on('click', function(e){
    e.preventDefault()
    Swiper1.swipeNext()
  })

   var Swiper2 = new Swiper('.s2',{
    pagination: '.p2',
    loop:true,
    grabCursor: true,
    paginationClickable: true
  })
  $('.al2').on('click', function(e){
    e.preventDefault()
    Swiper2.swipePrev()
  })
  $('.ar2').on('click', function(e){
    e.preventDefault()
    Swiper2.swipeNext()
  })

 $('#shots_button').on('click', function() {
      Swiper2.resizeFix() ;
      Swiper2.reInit() ;
  });
  </script> 

Answer №1

For the most recent versions of Swiper, it is recommended to utilize the 'update' method on the Swiper instance instead of reInit() or resizeFix(). This has been tested on Swiper 3.4.2:

 $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    slider.update(); 
 }

Answer №2

So, I found the solution to my issue. It turns out that the problem was related to using bootstrap tabs. Here is the code snippet I used:

 $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        slider2.resizeFix(true);  
        slider1.resizeFix(true); 

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 to Use Angular 8 to Filter an Array of Objects Based on Numeric Values

Can the list be filtered based on the value of iseidaCcaa.id? var centers = [ { id: 2, nombre: "Centro 2", iseidaCcaa: { id: 1, }, }, { id: 3, nombre: "Centro 3", iseidaCcaa: { id: 1, }, }, { id: 1 ...

Using localStorage in an Angular template: a comprehensive guide

Currently, I am facing some issues with localStorage on a website as I am unable to get a * ngif directive to function as desired. To provide further context: When a user logs in, their information is stored in the localStorage under the 'identity&ap ...

What is the technique for choosing the parent's ID with jQuery?

When a user clicks on any team, I need to retrieve the parent's parent ID. For example, if someone clicks on a Premier League Team, I want to store the ID 2 in a variable called league_id. Here are my attempts so far: Using Closest Method $('u ...

An error was encountered because it was unable to read properties of undefined, specifically in trying to access 'navigate'

Just diving into the world of react native and react navigation, I encountered this puzzling error. Uncaught TypeError: Cannot read properties of undefined (reading 'navigate') I'm scratching my head because I am using the exact same code ...

Tips for personalizing the export grid menu in angular-ui-grid?

My grid includes an external "Show Details" option that adds extra columns to the grid when clicked. https://i.sstatic.net/Fu2Qp.png The problem arises with the options for "Export all data" and "Export visible data," which can be confusing in this scena ...

Operating PhantomJS in server mode

I am considering using PhantomJS to convert a dynamic AngularJS application into static HTML that can be searched by Google. My plan is to set up a PhantomJS server behind a proxy to handle the ?escaped_fragment requests. While I know that PhantomJS is pri ...

Recreate body content with JQuery Mobile

I've been attempting to duplicate the entire HTML content within the tags. However, even though the appearance on screen is correct, none of the links are functioning.</p> <p>To view the fiddle, click here: [Here is a fiddle][1]</p> ...

Preserving scroll location following a hyperlink postback situation

I've explored numerous strategies to tackle my issue, but none have proven successful. My task involves toggling user activation and deactivation through an asp.net hyperlink. The main problem arises when this action triggers a postback, causing the p ...

Exploring the depths of code coverage with Nightmare.js

Quick version: I'm struggling to view the code coverage for my tests written with nightmare.js and mocha. I've attempted using istanbul and _mocha, but haven't had any success yet. Detailed version: I'm working on a small project: / ...

Ways to verify whether a user is not defined

My code includes a command that sends a Direct Message to a user, with the user being specified as follows: let user; if (message.mentions.users.first()) { user = message.mentions.users.first(); } else if (args[0]) { user = message. ...

Why does my page keep refreshing even after I close the model?

I am facing the following issues: 1- Whenever I try to close my model by clicking 'cancel', it causes the page to reload. 2- Clicking 'OK' does not send the 'DELETE' request to the server, nothing is received, and the page r ...

Minimizing Jitter in HTML5 and JavaScript Applications

I am currently working on developing a metronome as a hobby using JavaScript/HTML5 with the intention of turning it into a FirefoxOS app. One issue I've encountered is Jitter, which is unacceptable for Metronomes. As JavaScript is single-threaded and ...

The design elements are not being implemented on my custom React library built with TypeScript

I recently created a React library called https://github.com/deadcoder0904/react-typical/ and added styles to the component in the examples/ directory. However, I've noticed that the styles are not being applied. Below is the content of the example/i ...

Can you please provide guidance on implementing automatic horizontal scrolling with pauses between each div?

setInterval(function scroll() { $(".box_auto").each(function(i, e) { $("html, body").animate({ scrollTop: $(e).offset().top }, 500).delay(500); }); setTimeout(function() { $('html, body').animate({ scrollTop: 0 } ...

Header and sections with fixed positioning

The header has the fixed positioning property applied to it, causing the independent section to be impacted by this style rule. header{ position: fixed; top: 0; left: 0; width: 100%; padding: 25px 40px ; display: flex; just ...

Updating the text of one option within a selected option using jQuery while iterating through each element in a function

Hey there, I have multiple rooms each with two select dropdowns. My problem is that when I choose the option with a value of 4 in the number of persons dropdown, I only want the text of the next option (the dinner select) to change under the room I selecte ...

Increase or decrease values by clicking on Material UI IconButton

Looking to incorporate the functionality of an onClick() event for a Material UI IconButton that can either increase or decrease the Calories value for each item in the table. I've referenced the code from the Table React component page. https://i.ss ...

Using MutationObserver in an iFrame with JavaScript

I currently have an iframe that is loaded with the source www.abc/main.html <iframe id="my-iframe" src="http://www.abc/main.html"></iframe> The main.html file from abc imports and runs some JavaScript files. My goal is to utilize a MutationO ...

The TypeScript error message states that a value of 'undefined' cannot be assigned to a type that expects either a boolean, Connection

I've been grappling with this code snippet for a while now. It was originally written in JavaScript a few months back, but recently I decided to delve into TypeScript. However, I'm struggling to understand how data types are properly defined in T ...

Tips for navigating through an array incrementally in a Controller using input provided by the user in the View

Greetings, I am currently working on a small website project using WAMPserver. The site is structured following an MVC design pattern. In one part of the process, I generate an array of strings in the controller. My goal is to display each element of this ...