Only one tab can be open at a time, and when clicking on another tab, the focus will shift to that tab

My main concern is opening one tab at a time. The issue lies in the fact that when a tab is open and another tab is clicked, the height of the first tab reduces and the section tab title moves to the top of the screen making it invisible to the user. I want the focus to shift to the newly clicked tab on top of the body screen.

In sequential fashion, each tab should move to the top as the previous one becomes invisible to the user after clicking on a new tab.

If anyone can assist with this issue.

Answer №1

It appears that you are looking for...

Simply add this code snippet to the end of your $(".tab-header").click() function:


        var clickOffset = this.offsetTop;
        setTimeout(function(){
            // I'm not very familiar with jQuery, so I'm using vanilla JavaScript here.
            document.querySelector(".product-tabs-section").scrollTo({
                top: clickOffset,
                behavior: 'smooth'
            });
        }, 400);
        // The duration of jQuery fadeIn("fast") is 200ms,
      // but sometimes it takes longer than that,
      // So I added some margin for error.
    

Result

// Multiple tabs functionality begins //
    $(".tab-content").hide();
    $(".tab-content:first").show();

    $("ul.tabs li").click(function () {

        $(".tab-content").hide();
        var activeTab = $(this).attr("rel");
        $("#" + activeTab).fadeIn("fast");

        $("ul.tabs li").removeClass("tab-active");
        $(this).addClass("tab-active");

        $(".tab-header").removeClass("m_tab_active");
        $(".tab-header[rel^='" + activeTab + "']").addClass("m_tab_active");
    });

    $(".tab-header").click(function (e) {

        $(".tab_content").hide();
        var m_tab_activeTab = $(this).attr("rel");
        $("#" + m_tab_activeTab).slideToggle();

        $(".tab-header").removeClass("m_tab_active");
        $(this).addClass("m_tab_active");
        $("ul.tabs li").toggle("tab-active");
        $("ul.tabs li[rel^='" + m_tab_activeTab + "']").addClass("tab-active");

        var clickOffset = this.offsetTop;
        setTimeout(function () {
            // I'm not very familiar with jQuery, so I'm using vanilla JavaScript here.
            document.querySelector(".product-tabs-section").scrollTo({
                top: clickOffset,
                behavior: 'smooth'
            });
        }, 400);
        // The duration of jQuery fadeIn("fast") is 200ms,
          // but sometimes it takes longer than that,
          // So I added some margin for error.
    });
    // Multiple tabs functionality ends //

            /* Your custom CSS styles go here */
        

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div id="your-custom-html-id" class="shopify-section">
                <div class="your-custom-section">
                    <p>Your custom content goes here</p>
                </div>
            </div>
        

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

Using jQuery to load and parse a JSON file stored on a local system

I am a beginner in scripting languages and recently searched for ways to load and parse JSON files using jQuery. I found helpful resources on Stack Overflow. The JSON file I am working with is called new.json. { "a": [ {"name":"avc"}, ...

Sending information to components in Angular using Router

Should I pass data through the angular router to a component, or is it better to use a service? Currently, the component is receiving data in the following way: this.account = activatedRoute.snapshot.data.account ...

Ways to specify the specific option within a select field

Here is my question: <select name="currency" id="currency"> <option value="AUD"&lgt;AUD</option> <option value="BDT"&lgt;BDT</option> <option value="EUR"&lgt;EUR</option> & ...

The Bootstrap navbar appears to extend beyond the content on the page

I am new to using Bootstrap. I have encountered an issue with the navbar on my website. The navbar appears to be longer than the screen size and the right button is being overlapped by the right side of the window. Unfortunately, I am unable to scroll the ...

Troubleshooting issue with Gulp watch on Node v4.6.0

I'm currently facing a frustrating situation. I had a project up and running smoothly with a functioning gulpfile.js file, everything was perfect until I updated node to version 4.6.0. When I tried to report this issue on Gulp's git repository, t ...

Yii2 HTML helper input must be marked as required

This is the form I have generated using the HTML helper: <div class="row"> <div class='form-group col-lg-6 col-sm-6'> <?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-l ...

Using jQuery to adjust the length of a string to fit within a specific width

I am working with a table and need to input strings in each cell, but they are wider than the cell width. I want to shorten the strings without breaking lines, and add '...' at the end to show that the string is long. The table consists of aroun ...

Creating a list of objects in ReactJS

Currently, I am attempting to iterate through object properties (using "Name" as an example) and list them within a loop in a function. The method I have come up with seems quite clumsy and doesn't feel optimal. Here is the code snippet: const Ite ...

Chose to conceal all child elements, but is unable to reveal all elements when clicked

Currently, I am in the process of creating a jQuery accordion by following the tutorial provided on css-tricks at this link. After making some modifications to the code, I was able to hide all the elements within the parent element. However, upon clicking, ...

Encountering a data property error while trying to render ejs using axios

I am encountering an error message "TypeError: Cannot read property 'data' of undefined" when trying to display results.ejs using data from an API. Can someone help me identify what's incorrect with the rendering code? Thank you. index.js: ...

Unusual JavaScript Variable Glitch

I've been developing a Rock, Paper, Scissors game on JSFiddle, and I'm facing an unusual issue. Regardless of user input or the actual game outcome, two losses are being incorrectly added to the loss counter. I've been unable to pinpoint the ...

Determine if an option is chosen in multiple select elements using Vanilla JavaScript

In order to determine if a checkbox is checked, we use the following code: let isChecked = event.target.checked But what about multiple select options like the example below? <select name="books[]" multiple> <option value="A">A</option& ...

The code is malfunctioning on this site (yet functions perfectly on a different website)

So I have a question that may seem silly, but it's worth asking. I'm attempting to create a sticky div element that stays in place when you scroll past a certain point on the page. This is the script I have: <script type="text/javascript"> ...

Tips on configuring the values of the outer div in an HTML document

I have a webpage in AngularJS. It consists of two main sections; one displays the total number of users and the other displays a table populated with user data retrieved from a service. Below is the code snippet: app_user.html // This div displays the t ...

Guide to making axios/api calls in a Nativescript mobile application

In my development process, I am working on creating a small application using Nativescript-vue. This application requires backend functionality that is built on the laravel framework for making API calls to retrieve relevant data. For example, when a user ...

Is Angular capable of displaying a date within a specific timeframe using ng-show?

So I have a button that, when clicked, displays a list of data. I am adding a unique font awesome icon in there if the JSON key value exists. However, here lies the issue. The particular key happens to be a date. I need my ng-show function to check whether ...

The error has not been handled properly and is being thrown at line 174 in the events.js file

I encountered an issue while trying to request data from an API, resulting in a crash on any Windows server. Can someone lend a hand with this problem? Here is a snippet of my code: app.get("/js/2806/api/products/getAllDrugs", (req, res) => { co ...

Is it possible to include a shared helper text for two textfields that have been imported from MUI in a React.js project?

This snippet contains the code for my password container: .password-form-container { width: 85%; height: 7%; position: relative; top: 230px; left: 40px; display: flex; justify-content: space-between; border: 1px solid red; } <div clas ...

Optimizing Rendering Performance: Comparing the Impact of Multiple Stylesheets vs. Single Dynamic CSS on Dynamic CSS

Currently, I am in the process of developing a website that supports "plugins" as external "displays". These plugins consist of custom full-screen HTML content managed by a client-provided JavaScript driver. The website engine utilizes an API to allow thes ...

Strange occurrences of radio buttons in AngularJS

When working with radio buttons, I noticed a strange behavior that I wanted to share. My goal was to have Radio Button 1 selected if the array is undefined, and Radio Button 2 selected when the array is defined. In the initial state, the array is indeed ...