Skip Navigation

[Resolved] Image slider not showing inside tab

This thread is resolved. Here is a description of the problem and solution.

Problem: I'm using a custom tab solution to display a View inside a tab panel that is hidden upon page load. An Image Slider included in the View does not appear when I click the tab to expose the tab panel containing the View. If I resize the browser window, the Image Slider appears.

Solution: You may need custom code here. Use JavaScript to trigger a window resize event manually when the tab change event has occurred.

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by aaronW-4 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1861735

I am trying to:
I added tabs to a page using css and inserted a different view in each one. One of the views shows images from chid posts. It is conditional to show one or multiple images based on if there is one or more than one image present in the child post. For some reason, the image slider doesn't show its images until I resize my browser window.

You can log in here:
hidden link

Then go to :
hidden link

and click the "Contributions" tab. You will see the image slider doesn't show the images. Do you know what might be the issue here and how to fix it?

Link to a page where the issue can be seen:

I expected to see:

Instead, I got:

#1861759

Hi, the slider probably can't calculate the available space immediately because of something in the tab CSS, or it could be related to the JavaScript error I see in the console:

Uncaught TypeError: Cannot read property 'addEventListener' of null
    at owpSidrDropdown (main.min.js?ver=1.9.0:1)
    at HTMLDocument.<anonymous> (main.min.js?ver=1.9.0:1)

Hard to tell offhand. It seems the JavaScript from the theme's main.min.js file is expecting an element with the CSS class "mobile-menu" to exist in the DOM, but not finding it on this page. That triggers a JavaScript error, which could be causing a cascading issue where the slider is not initialized properly until the window resizes. As a test, you could try adding some empty span or div with the CSS class "mobile-menu", confirm the JavaScript error is no longer shown in the console, then test the tab/slider once again.

Or, upon clicking a tab that contains a slider, you can try triggering a window resize event programmatically:

// add this in some click event handler for your tabs
var evt = window.document.createEvent('UIEvents'); 
evt.initUIEvent('resize', true, false, window, 0); 
window.dispatchEvent(evt);

How you implement that depends on how your tabs are programmed.

#1863003

Right now I am just using css to show and hide specific tab containers when one is clicked. I don't think I'm well-versed enough in javascript to implement this.

#1863541

Okay it looks like you're using radio input 'checked' state in your CSS selectors to determine which tab is visible. You can use jQuery's input 'change' event handler to trigger code based on those radio input change events like this:

jQuery(document).ready(function(e){
  var evt = window.document.createEvent('UIEvents'); 
  evt.initUIEvent('resize', true, false, window, 0); 
  window.dispatchEvent(evt);
  jQuery(document).on('change', 'input[name="tabs"]', function(e){
    window.dispatchEvent(evt);
  });
});

Try adding that JavaScript snippet to the page once, either in the post Content Template's JS editor or in a JS file enqueued in your theme.

However, you may need help from your theme developers to solve the other JavaScript error I mentioned. That issue does not seem to be related to Toolset as far as I can tell.

#1863689

Works perfectly! Thank you for your help!