Aligning a div between the page margins with a single click

I am attempting to compile a list of products with a concealed div inside. Upon clicking on the product, the hidden div should reveal and display details.

If you inspect the fiddle, you'll notice that the final hidden div protrudes beyond the margins when activated.

Using jQuery to unveil the hidden div:


function activateDropdown(entry_id) {
    $(".box-dropdown").hide("slow");
    $("#box-dropdown-" + entry_id).show("slow");
}
    

Is there a technique to "align" it while adhering to the margins? (Given that the site is responsive, the number of green divs might decrease to 3 or even 2 as the viewport size decreases...)

Recent Developments:

  • The opened hidden square should have dimensions of 4x4 and be positioned above the other three divs. View updated fiddle.

  • The hidden div should expand from left-to-right, but in the case of the last square, it ought to enlarge right-to-left.

Answer №1

check out the live demo

If you want to achieve the effect of opening divs from right to left, there are two key changes that need to be made:

Firstly, specify how the divs should behave in the DOM when opening from right to left. If it's a fixed dive, consider using a property like nth-child(4n).

#box-dropdown-4{
    right:0;
}

Secondly, add a condition in your JavaScript for the divs that will open from right to left. You can use something like entry_id%4 == 0 to identify the 4th div.

if (entry_id != 4) {
        $("#box-dropdown-" + entry_id).show("slow");
    } else {
        $("#box-dropdown-" + entry_id).show('slide', {
            direction: 'right' /* choose slide direction */
        }, 20000);
    }

Important note: I'm not very experienced with JavaScript, so the animation may not be super smooth :)

Answer №2

To style the element, apply this CSS:

   #box .box-dropdown {
            display: none;
            width: 100%;
            height: 100%;
            background: #ffffff;
            position: absolute;
            z-index: 5;

        }

View Demo

The following changes have been made :

width:100%;
height:100%;

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

Is there a way to access and parse a CSV file from a URL within a Next.js project?

Currently working on a Next.js application available here. The task at hand requires reading a CSV file from a specific URL within the same repository in multiple instances. Unfortunately, I am encountering difficulties retrieving this data. You can locate ...

Make sure the image is aligned in line with the unordered list

I've been having trouble trying to display an image inline with an unordered list. Here's the HTML code: <div class="customer-indiv man"> <a class="customer_thumb" href="/fan/332profile.com"> <img src="http://i.imgur.com/Wi ...

How to use jQuery to slide down a specific element?

One challenge I am facing is with a jQuery function that triggers a slideDown animation on a specific element when clicked: $('.Minimize').click(function() { $('.ContentTD').slideUp('slow', function() { ...

Endless loading on NodeJS server local host

My NodeJS setup is serving files, but the page seems to be stuck loading. Here's a snippet from my index.js file: const express = require("express"); const path = require("path"); const http = require("http"); const socke ...

Exploring Cross Origin Policy Restrictions with Fiddler for JSON Debugging

In the process of creating a modern webapp using JSON data, I came across a helpful blog post about using Fiddler to mock JSON data. My development setup involves working locally with Notepad++ and testing primarily on Chrome, with plans to expand to othe ...

Transitioning from using a jQuery get request to utilizing Vue.js

Looking to transition from JQuery-based js to Vue as a newcomer to JavaScript. Seeking guidance on making a get request and displaying the retrieved data. What approach would you recommend for this task? Here's the HTML snippet: <div> <di ...

convert a string to JSON format using Node.js Express

Currently, I am viewing some string data in a browser that has been processed using python-node js express. The data looks something like this: In order to manipulate the data more effectively, I would like to convert it into JSON format that follows this ...

Version 4.6.4 of TypeScript is flagging the code as invalid

How can I fix this Typescript problem? const userInformation: { email: string; id: string; _token: string; _tokenExpirationDate: string; } = JSON.parse(localStorage.getItem('userData')); https://i.sstatic.net/xMh9P.pn ...

Unable to establish a connection with the endpoint

I'm encountering an issue while trying to connect to the endpoint on the server. Below is the code snippet: Register.jsx function Register() { const [registerUser, setRegisterUser] = useState({ username: "", email: "", password: "", ...

multiple event listeners combined into a single function

I'm looking to streamline my button handling in JavaScript by creating just one function that can handle all the buttons on my page. Each button will trigger a different action, so I need a way to differentiate between them. I thought of using one eve ...

Unlocking the Mysterious Realm of HTML

I recently stumbled upon a mysterious combination of HTML attributes: <div vanisheffect="true" blinkcolor="red" fadeopacity="0.8"> Have you ever encountered something like this? And more importantly, does it have any impact on specific browsers? Is ...

Encountering errors while attempting to render MUI components in jsdom using react testing library within a mocha test

Due to the lack of maintenance and support for React 18+ in enzyme, I am faced with the task of migrating over 1750 unit tests to work with react-testing-library and global-jsdom. This migration is necessary so that our application can continue running on ...

Bot on Discord engaging in a gaming session

I recently developed a Discord bot with the status of ""playing a game"" and here is the code that I implemented: bot.on('ready', () => { console.log('Client is online!'); bot.user.setActivity('osu!'); Th ...

Clicking React useState causes it to update before the intended click is registered

My goal is to create 50 buttons that, when clicked, will update the value of useState to the current button number (array index+1). However, I've encountered an issue where I have to click a button twice to get the correct value. The first click alway ...

Cross domain Ajax POST requests using CodeIgniter and AjaxBy utilizing CodeIgn

Initially, I would like to clarify ... I own two domains: www.one.com and www.two.com The first domain www.one.com has a form input below <div class="hidden cswrap2"> <h3>Edit Data Mustahik</h3> <div class="cscontent"> ...

Please provide the date using the Foundation Datepicker tool

Beginner in JavaScript here! I am having an issue with submitting dates selected using the Foundation Datepicker from . I have searched for solutions on StackOverflow like Post form on select with JQuery Datepick, but none seem to work in my case. If a Ja ...

Tips for retrieving data from a concealed input within a div that is being looped through in Angular.js

Currently, I have a controller that sends data to the UI and uses the ng-repeat directive to map them. My next goal is to bind this data with a hidden input form and then send it to another function in the controller when a click event occurs. Any tips on ...

jQuery mobile page load event is failing to trigger

<div id="order-preview" data-role="page"> // header //ui-content //footer <script> $("#order-preview").on("pageload",function(event){ alert("aas"); }); $(document).on("pageload","#order-preview",function(event){ alert( ...

Can you explain the purpose and significance of addEventListener()?

class MyController{ public myEntities = ko.observableArray(); constructor(modelData) { var me = this; me.onViewLoaded.addEventListener(() => { me.myEntities.push(modelData); }); } The ...

Is there a way to display the "back button" on a subview?

As a newcomer to Ionic, I am finding navigation to be the most challenging aspect. My app has two tabs - "Dashboard" and "Friends". When I click on the Dashboard tab, I want it to navigate to a subview called "subview_dash", without displaying the tabs in ...