Navigating up and down in a horizontal row of 'tabs'



For a school project, I am in the process of creating a website that I wanted to make unique and different. However, I have encountered a major challenge with a tight deadline approaching. Any assistance would be greatly appreciated.

Let's address the problem at hand:


I chose to structure my site with four "tabs" implemented as separate pages within their own div elements. When a user clicks on a link, a small piece of JavaScript is triggered to set the left property based on the current page being viewed relative to the screen width.

For example: If the user is viewing page 1, then for page 0 x=-1; for page 2 x=2; and for page 3 x=3. Likewise, if page 3 is being viewed, for page 0 x=-3; for page 1 x=-2; and for page 2 x=-1.

By applying position: fixed; to each tab's div id and adding a transition, I can achieve a smooth sliding animation when switching between pages while keeping the other tabs fixed off-screen to the left or right.

The issue arises with the need for vertical scrolling on each tab, which seems unattainable due to the fixed div positions. I experimented with alternative positioning properties like relative and floating elements simultaneously but encountered layout distortions such as cascading tabs.

Referencing a mock-up of my code on JSFiddle revealed issues (link provided) that prevented me from achieving the desired functionality. The CSS and HTML code snippets showcase my attempts to tackle the problem by utilizing fixed positioning:

#container {
    display: block;
}
nav {
    position: fixed;
    display: block;
}
#homeTab, #xTab, #yTab, #zTab {
    position: fixed;
    top: 50px;
    transition: 2s;
    -webkit-transition: 2s;
    -moz-transition: 2s;
    -o-transition: 2s;
    -ms-transition: 2s;
}

Integrating these styles into the document along with JavaScript logic positioning the tabs dynamically posed challenges with scrollability while maintaining horizontal tab navigation. Unfortunately, jQuery solutions are not viable for me due to time limitations and lack of expertise.

If you have any suggestions on improving this setup to enable vertical scrolling within the tabs alongside the existing horizontal navigation, your insights would be invaluable. Thank you for your assistance in advance.

Answer №1

Do you want something as simple as this? (only involves overflow attribute) http://jsfiddle.net/InferOn/C8KgM/

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
      #container {
        display: block;
      }

      nav {
        position: fixed;
        display: block;
      }

      #homeTab, #xTab, #yTab, #zTab {
        position: fixed;
        top: 50px;
        transition: 2s;
        -webkit-transition: 2s;
		-moz-transition: 2s;
        -o-transition: 2s;
        -ms-transition: 2s;
      }

      .ttab{
      height:300px;
      overflow-y:scroll;
      }
    </style>
</head>
<body>
  <header>
    <nav>
      <a href="#homeTab" onclick="page(0);" title="Home">home</a>
      <a href="#xTab" onclick="page(1);" title="x">page x</a>
      <a href="#yTab" onclick="page(2);" title="y">page y</a>
      <a href="#zTab" onclick="page(3);" title="z">page z</a>
    </nav>
  </header>
  <div id='container'>
    <div id="homeTab">
      <p>Home page</p>
    </div>
    <div id="xTab" class="ttab">
      <p>Page X... [Content Hidden for Brevity] ...X</p>
    </div>
    <div id="yTab" class="ttab">
      <p>Page Y... [Content Hidden for Brevity] ...Y</p>
    </div>
    <div id="zTab" class="ttab">
      <p>Page Z... [Content Hidden for Brevity] ...Z</p>
    </div>
  </div>
</body>

<script>
  var container = document.getElementById('container');
  var homeTab = document.getElementById('homeTab');
  var xTab = document.getElementById('xTab');
  var yTab = document.getElementById('yTab');
  var zTab = document.getElementById('zTab');

  if (typeof window.innerWidth != 'undefined') {
    var vpwidth = window.innerWidth;
  }

  homeTab.style.width = vpwidth + 'px';
  xTab.style.width = vpwidth + 'px';
  yTab.style.width = vpwidth + 'px';
  zTab.style.width = vpwidth + 'px';

  /** POSITIONS THE TABS BASED ON WHICH TAB SHOULD BE SHOWN **/
  function page(tab) {
    switch (tab) {
      case 0:
        homeTab.style.left = '0px';
        xTab.style.left = vpwidth + 'px';
        yTab.style.left = 2 * vpwidth + 'px';
        zTab.style.left = 3 * vpwidth + 'px';

        break;
	  // Additional cases omitted for brevity
      default:
        homeTab.style.left = '0px';
        xTab.style.left = vpwidth + 'px';
        yTab.style.left = 2 * vpwidth + 'px';
        zTab.style.left = 3 * vpwidth + 'px';
        break;
    }
  }
  page(0);
</script>

</html>

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

Error: The $filter function in AngularJS is not recognized

I have been attempting to inject a filter into my controller and utilize it in the following manner: angular .module('graduateCalculator', []) .filter('slug', function() { return function(input) { ...

Extracting the input's data and placing it into a table cell

Hey there! I am facing an issue where the data entered in the input fields is not getting transferred to the respective <td>. The text displayed in the (tabios) field should change according to what is entered in the input. Here's the code snipp ...

Tips for restricting function invocations in JavaScript?

I am seeking a function called limitCalls(fn, maxCalls) which accepts a function fn and creates a new function that can only be called the specified number of times in maxCalls. Here is a test example: it('limitCalls', () => { const makeIncre ...

Using Javascript to Swap the Content of an Element

Recently, I've been delving into the world of javascript and have hit a roadblock. I understand how to instruct javascript to set a specific value for an ID, but now I have a new challenge: I want to create javascript code that can retrieve informati ...

Sails.js seems to be malfunctioning, as it does not seem to be recognizing the term 'sails'

It seems like I'm encountering an issue with the 'sails' command not being recognized on my Windows 10 system. Despite following all the installation steps, including globally installing Sails.js through npm and ensuring Node is installed, I ...

Adding information to Google Cloud Firestore while disconnected from the internet

I am currently facing an issue with my code. It works perfectly fine when the application is online, but fails to execute the promise resolution or rejection when offline. I have searched through the cloud firestore documentation and found examples on qu ...

Exploring methods for monitoring page transitions in Next.js

Looking to repurpose a menu I created in react using react-router-dom for use in nextjs. My objective is to update the menu state to 'false' and change the menuName to 'menu' upon clicking on a link within the menu. Implemented a useEf ...

Updating line connections between objects in Three.js while rendering

I am working with a three.js canvas that contains circles moving independently. Initially, these circles are connected by a single line that follows the same geometry as their positions. However, I am facing difficulty updating the line's geometry wh ...

What could be causing the lack of responsiveness in my font size when adjusting to different screen sizes?

My understanding was that using font-size: 4em; would result in a relative size, but I am facing an issue where the font size remains constant regardless of window size. This causes overlap and makes the text look unattractive. Specifically, the text in qu ...

Having issues with setting up nodejs on kali linux

Whenever I try to execute the configure script ./configure for nodejs installation, it fails to run successfully. Traceback (most recent call last): File "./configure", line 19, in <module> from distutils.spawn import find_executable ModuleN ...

CSS problem: Footer encroaching on the content above

For more information, please visit this link When the window is minimized, the footer overlaps the content above it. Despite spending hours trying to fix this issue, I have not been successful. View when maximized: here View when minimized: here Even af ...

Using Angular: Dynamically load an external JavaScript file after the Component View has finished loading

In my Angular 5 application, I am faced with the challenge of loading a JavaScript script file dynamically after my component view has been fully loaded. This script is closely related to my component template, requiring the view to be loaded before it ca ...

Top method for identifying "abandoned words" within text that has been wrapped

Our content and design teams have a specific request to prevent paragraphs from ending with an "orphan word" - a single word on the last line of text that has wrapped onto multiple lines. The designer's proposed solution is to adjust the margins sligh ...

What is the best way to ensure that TwentyTwenty.js images are always positioned in the

Looking to utilize the TwentyTwenty.js code for image comparison, but facing an issue where the images are aligned to the left side. Is there a way to keep them centered without explicitly setting the width on the container? <div id="beforeafter" class ...

ways to assign local file path as image url in json

Hey there, I am a new tool for angularjs. Take a look at the json file below: [ { "name": "WORLD", "population": 6916183000, "flagurl":"C:\xampp\htdocs\selva \Flag_of_the_People's_Republic_of_China.svg" }, { "na ...

Tips for customizing ngTable with expandable detail panels

I am currently working on styling a layout using ng-table, which includes a table within each row. The expanding functionality in Angular is implemented as follows: <tr ng-if="org.expanded" ng-repeat-end> <td></td> <td></td& ...

Is it possible to have a div set to close upon loading the page?

Is there a way to have the toggle function set up so that when the page loads, the div being toggled starts out closed? I don't want them to be visible until clicked on. Best regards, Joey <script type="text/javascript> $(document ...

What is the best way to position the top line next to the border?

I've been attempting to create a falling line effect on the left side of the box's border, but I can't seem to figure out what's causing the issue. Below is the code snippet: @import url('https://fonts.googleapis.com/css ...

The collapsible navbar vanished, where did it go?

While experimenting with the carousel template page, I noticed that the NavBar collapses when the screen width is reduced below a certain pixel size. Initially, everything was working fine as intended. However, after making some modifications to the carou ...

Choose a list in order to create a new list

If I were to choose a specific state in Nigeria, what steps should I follow to generate a drop-down menu with a list of local governments within that state? ...