Gap positioning at the upper part of the listing area

After finding a design on a website that caught my eye, I decided to make some alterations to fit my needs.

The original demo had a vertical layout but I wanted the elements side by side. To achieve this, I created a table with two columns and 100% width. However, something strange happened when I added the lists inside the table.

I found an unexpected gap between the lists even though there was no padding set on top or any other objects interfering. Both the list and the table were aligned vertically. For better reference and assistance, I have included a link to a demonstration in JSFiddle.

If you could provide insight or solutions, it would be greatly appreciated. Thank you!

<table width="100%" border="0">
<tbody valign="top">
<tr valign="top">
  <td valign="top">
  <ul class="tabs">
      <li class="tabs__item color1">
        <h2><span>[Review] The New LG G18</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color2">
        <h2><span>[ROM][8.3.1] SlimSaber R31</span> </h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color3">
        <h2><span>[APP] Goo Simulator Extreme</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color4">
        <h2><span>[Tutorial] Pooping Your Pants</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <div class="views-toggle views-toggle--hidden">
        <svg fill="white" viewBox="0 0 24 24">
          <path d="M16.59 8.59l-4.59 4.58-4.59-4.58-1.41 1.41 6 6 6-6z"/>
          <path d="M0 0h24v24h-24z" fill="none"/>
        </svg>
      </div>
    </ul>
    <script       src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <script src="js/index.js"></script> 
  </td>
  <td valign="top">
  <ul class="tabs">
      <li class="tabs__item color1">
        <h2><span>[Review] The New LG G18</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color2">
        <h2><span>[ROM][8.3.1] SlimSaber R31</span> </h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color3">
        <h2><span>[APP] Goo Simulator Extreme</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <li class="tabs__item color4">
        <h2><span>[Tutorial] Pooping Your Pants</span></h2>
        <p class="tabs__stats">Content</p>
      </li>
      <div class="views-toggle views-toggle--hidden">
        <svg fill="white" viewBox="0 0 24 24">
          <path d="M16.59 8.59l-4.59 4.58-4.59-4.58-1.41 1.41 6 6 6-6z"/>
          <path d="M0 0h24v24h-24z" fill="none"/>
        </svg>
      </div>
    </ul>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <script src="js/index.js"></script> 
  </td>
 </tr>
 </tbody>
  </table>

Answer №1

Below is the necessary code for the moveTabs function

 var indexOffset = 0;       
  tabs.each(function(index) {
    if ($(this).hasClass('tabs__first'))
       indexOffset = index-1;

    transY  = (index-indexOffset) * 10;        
    scale       = 0.5 + (index-indexOffset)/25;

Make sure to add a tabs__first class to the first item you want to "reset"

Here's how it works --

  • Within the loop, I check for the tabs___first marker and if found, I set my offset to one less than the index

  • When applying the transformation on the item, instead of using the index directly for transformation like in the original code, I now use index minus indexOffset.

fiddle - https://jsfiddle.net/s4sc2mu1/2/

Answer №2

The problem at hand arises from the fact that the javascript determines the vertical placement of the boxes on the page according to their position in a list.

transY = index * 10;

I've kept a backup of the code snippet (http://jsfiddle.net/dh286ksq/4/), but here are the modifications required:

Assign an id to both unordered lists:

<ul class="tabs" id="list1">

<ul class="tabs" id="list2">

Add two additional lists in the javascript section based on the new IDs:

var tabs = $('li.tabs__item'); // current list
var tabs1 = $('#list1 li.tabs__item'); // new list
var tabs2 = $('#list2 li.tabs__item'); // new list

Also, change the following in the javascript:

tabs.each(function(index) {
    transY = index * 10;
    scale = 0.5 + index/25;

    transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
});

to this:

tabs1.each(function(index) {
    transY = index * 10;
    scale = 0.5 + index/25;

    transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
});

tabs2.each(function(index) {
    transY = index * 10;
    scale = 0.5 + index/25;

    transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
});

The objective is to obtain separate lists for the two columns and then utilize the javascript to arrange the box positions based on these distinct lists. By doing so, each column will begin indexing at 0 instead of carrying over from the previous column.

Answer №3

In my opinion, this solution addresses the issue:

var Tabs = (function() {

  var toggler = $('.views-toggle');
  var tabs      = $('li.tabs__item');
  var toggled = false;

  var transform = function(el, value) {
    el.css('transform', value);
    el.css('-webkit-transform', value);
    el.css('-ms-transform', value);
  };
   var transition = function(el, value) {
    el.css('transition', value);
    el.css('-webkit-transition', value);
    el.css('-ms-transition', value);
  };

  var moveContent = function() {
    if (!toggled) {
      toggled = true;
    } else {
      toggled = false;
    }

    moveTabs(toggled);

    return false;
  };

  var moveTabs = function(a) {
    var transY, scale;

    if (a) {
      tabs.css({
        'opacity': '1',
        'box-shadow': '0 30px 60px rgba(0,0,0,0.4)',
        'cursor': 'pointer'
      });

      tabs.each(function(index) {         

        transY  = $(this).index() * 10;        
        scale       = 0.5 + $(this).index()/25;

        transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
      });

      toggler.addClass('views-toggle--hidden');
    } else {
      transform(tabs, 'translate3d(0,0,0) scale(1)');
    }
  };

  var switchTabs = function() {
    var selected = $(this);
    var others = selected.siblings('li');

    if (toggled) {
      transition(others, 'transform 0.3s cubic-bezier(0.755, 0.05, 0.855, 0.06)');
      transform(others, 'translate3d(0, 100%, 0) scale(1)');
      transform(selected, 'translate3d(0,0,0) scale(1)');
      tabs.css({
        'box-shadow': '0 30px 60px rgba(0,0,0,0.4)',
        'cursor': 'default'
      });
      toggled = false;

      selected.on('transitionend webkitTransitionend', function() {
        toggler.removeClass('views-toggle--hidden');
        others.css({
          'opacity': '0'
        });
        transform(others, 'translate3d(0, 100%, 0) scale(0)');
        transition(others, 'transform 0.9s cubic-bezier(0.23, 1, 0.32, 1)');
        selected.off('transitionend webkitTransitionend');
      });
    }
  };

  var setup = function() {
    toggled = true;
    moveTabs(toggled);
  };

  var init = function() {
    $(document).on('ready', setup);
        toggler.on('click touchstart', moveContent);
    tabs.on('click touchstart', switchTabs);
  };

  return {
    init: init
  };

}());

Tabs.init();

https://jsfiddle.net/trn44k7j/5/

Answer №4

Within your Javascript code

  tabs.each(function(index) {
    transY  = index * 10;        
    scale       = 0.5 + index/25;

    transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
  });

The issue lies in the fact that the transformation is not being reset, causing the second column to be transformed as if it were appended to the first column.

A more effective approach is needed for setting "transY". Currently, it is being set based on the index within the list of "tab"s, resulting in tab 1 being shifted 10vh down, tab 2 at 20vh, and so forth.

An Easy Solution to Understand

If you anticipate having 4 "tabs" per column consistently, a hardcoded solution can be implemented by adjusting the above code snippet:

  tabs.each(function(index) {
    transY  = (index%4) * 10;        
    scale       = 0.5 + index/25;

    transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
  });

Alternatively, a revision of the logic for determining the y location of "tabs" may be required, taking into account factors beyond just the number of "tabs". This demonstration serves an educational purpose, highlighting the flaw in the initial logic and introducing a straightforward fix without intricate methods.

EDIT:

Resolution using Jquery Tree Navigation

A dynamic solution that avoids hardcoding and delves into a slightly more complex approach. The idea involves selecting every "tabs" list and iterating through each child element with the class "tabs__item", adjusting their positioning based on height dynamically. This method is fully adaptable and applicable to any scenario involving various numbers of "tab__item"s within different sets of "tabs", offering flexibility without requiring CSS file alterations or structural changes.

 $('.tabs').each(function(index) {
      $(this).children('li.tabs__item').each(function(index) {
          transY    = index * 10;        
          scale     = 0.5 + index/25;

          transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
      });
   });

JS Fiddle Link: https://jsfiddle.net/trn44k7j/8/

Answer №5

Have a look at this: https://jsfiddle.net/trn44k7j/3/

The interesting thing here is that each window is set with specific parameters based on its index value. However, the script seems to be counting ALL windows instead of just those in the particular cell. While this may not provide a definitive solution, it does highlight an area for further consideration. Here are my recent updates:

 tabs.each(function(index) {
          if (index % 4 == 1){
          index=1;
          }
          if (index % 4 == 2){
          index=2;
          } 
          if (index % 4 == 3){
          index=3;
          }          
          if (index % 4 == 0){
          index=0;
          }
        transY  = index * 10;        
        scale       = 0.5 + index/25;

        transform($(this), 'translate3d(0,' + transY + 'vh, 0) scale(' + scale + ')');
      });

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

Troubleshooting Problems with Cookie and Session Management

I'm encountering an issue while trying to set cookies and session values during login on the backend, which is built in node js. However, when react calls the API to verify these cookies or session values, they are returning as undefined... My middle ...

How can I utilize a variable in a v-for loop as a label for a q-btn in Vue.js?

I have a list: myList = [1, 2, 3, 4, 5, 6, 7, 8, 9] I'd like to generate buttons using this list where the label corresponds to the number: <q-btn v-for="number in myList" v-bind:key="number" color="primary" label=&q ...

How can I make Firefox render the padding in a textarea the identical way as in a div?

In my efforts to ensure a consistent line width inside a textarea across IE8, Firefox, and Safari, I have encountered an issue where Firefox seems to add an extra pixel of padding compared to the other browsers. This results in text wrapping differently an ...

React: Actions should only be simple objects

My project structure is set up as follows: https://i.sstatic.net/f1wdV.png In GlobalStore.js, I have the following code: import React from 'react' const GlobalContext=React.createContext(); const GlobalProvider=GlobalContext.Provider; const Gl ...

Could my HTML security measures be vulnerable to exploitation?

I have successfully developed a function that accomplishes the following: It accepts a string as input, which can be either an entire HTML document or an HTML "snippet" (even if it's broken). It creates a DOMDocument from the input and iterates throu ...

Whenever I attempt to populate my modal box with data from my selection, I am greeted with an error message stating "invalid object passed in." What could be causing this issue?

Whenever I click on a customer from my table to display their details in a modal box, I keep getting an error message that says "invalid object passed in." The method client is responsible for populating the data and displaying it through a partial view. T ...

Error: Unable to access 'push' property of null object in Next.js Link

Utilizing Vite to develop a reusable component has led to an error upon publishing and reusing it: TypeError: Cannot read properties of null (reading 'push') The code for the component is as follows: import React from "react"; import ...

What is the process for incorporating a personalized SVG file into the material-ui Icon Component?

For my project, I have a requirement to use custom svg files. To achieve this, I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0865697c6d7a616964257d61483b2631263b">[email protected]</a>. I reviewed ...

What is the best way to activate a function within an npm package in a Vue application?

I'm just starting out with Vuejs and I've recently installed the vue-countup-v2 npm package. I successfully imported it into my Vue component and noticed that it works perfectly when the page loads. However, I am interested in triggering the Coun ...

How to position a fixed width div in the center of a Bootstrap 4 layout with fixed header and footer

My fixed-width div needs to be precisely 816px wide. I want to center it on the page. Using the Bootstrap 4 Fixed Header/Footer layout with a body height of 100%, I tried using mx-auto for centering, which works well on desktop but causes a horizontal sc ...

The function Jquery .stop does not exist

I am encountering an issue with the magicline.stop function while attempting to implement an underline sliding effect for my navbar. I have tried to troubleshoot the problem but have been unsuccessful so far. Below is the code snippet: <nav class=" ...

Guide to refreshing a page (state) in a react application

As I delve into learning react.js, I decided to develop a basic rock paper scissors game within a react app. However, I've encountered some difficulty in creating a reload button that differs from the standard JavaScript button implementation which ty ...

Guide to showcasing firestore data on a react web application

Hello everyone, I'm new to this forum so please let me know if I have missed any important details. I am trying to figure out how to display data from my Firestore database on my React web application. Currently, I can see the data in the console of t ...

Using Wordpress? Customize your sidebar with three widgets and don't forget to add the "last" class to the third one for a polished look

Successfully set up a custom sidebar on my WordPress website and configured it to display three widgets. The CSS for the sidebar includes a specific styling for each widget, with an additional class to remove margin-right from the last (third) widget. reg ...

The initial material UI button conceals itself

I have encountered an issue with Material UI buttons in my code. Here's how I am using them: <main className="content"> <div className="buttons"> <Button variant="contained&qu ...

Adjusting my menu layout causes my header image to be partially covered

I've been trying to make my menu fixed at the top of my website, but it keeps overlapping into my header image and doesn't look right. I've experimented with different solutions, but nothing seems to work. Here's the CSS code I used th ...

Difficulty with jQuery's nth-child selector when using the n+2 argument within a table layout

I am experiencing some issues with the jQuery's nth-child selector in relation to the HTML code below. Instead of returning the expected result of (total number of SELECTs - 1), it is returning 0. Interestingly, when I remove the TABLE and only keep t ...

Refreshing Your WordPress Post Automatically

Can someone assist me with setting up an autorefresh feature for a specific div that has the ID of "blue"? I want the div to automatically update whenever I make changes to a post with that same ID. var auto_refresh = setInterval( function () { $('#b ...

Ways to extract the value from a jQuery object

How can I retrieve the selected time value using a jQuery plugin and save it on a specific input element within the page? Refer to the plugin and code provided below: http://jsfiddle.net/weareoutman/YkvK9/ var input = $('#input-a'); input.cloc ...

When I use the shift method on one array, it alters the contents of that array

I am encountering a peculiar issue with two arrays of objects in my program. One array is named "Responses" and the other is called "Questions." The problem arises when I remove the first element from an object in the "Questions" array using shift() meth ...