What are the steps for creating a div with a partially hidden element?

Is it possible to create a partially visible div on a webpage, similar to a footer, that slides up when clicked? This div will contain important information.

I have managed to achieve this to some extent, but the issue I am facing is that the div doesn't actually get hidden, rather it just changes its position.

You can view the demo by visiting: http://jsfiddle.net/8ZFMJ/394/

var clicked=false;
$(".two").on('click', function(){
    if(clicked)
    {
        clicked=false;
        $(".two").css({"bottom": -430});
    }
    else
    {
        clicked=true;
        $(".two").css({"bottom": "-200px"});
    }
});

Answer №1

A while ago, I encountered a similar issue which prompted me to ask my first question on StackOverflow. Unfortunately, the response was not very positive.

The issue at hand is that simply changing the position of the div by using ".bottom" is not enough. It seems what you really want to do is adjust the height instead. You can refer to this JSFiddle where I successfully switched the div between states (although without any animation yet).

This solution involves utilizing CSS's "overflow-y: hidden;" to conceal the contents of the div when it's small. The JavaScript code toggles between two different heights:

if(clicked)
{
    $(".two").css("height", 10);
}
else
{
    $(".two").css("height", 250);
}
clicked = !clicked;

The line clicked = !clicked simply changes the boolean state of the variable.

To incorporate animation, we can use jQuery's ".animate" method and create this visually appealing Fiddle.

In essence, all we had to do was replace the css with animate to achieve the desired effect. Pretty straightforward, right?

TL;DR
Check out the final version of the JSFiddle here.

Answer №2

.two should be positioned absolutely within the .container element, which should have a relative position. By adjusting the bottom property to a negative value, you can hide the footer.

CSS:

html, body { height: 100%; }
.container {
    position: relative;
    height: 100%;
    overflow: hidden;
}
.two {
    position: absolute;
    background-color: yellow;
    width: 100%;
    height:250px;
    bottom: -200px;
    transition: bottom 1s;
}

jQuery:

var clicked=false;
$(".two").on('click', function(){
    if(clicked)
    {
        clicked=false;
        $(".two").css({"bottom": "-200px"});
    }
    else
    {
        clicked=true;
        $(".two").css({"bottom": 0});
    }
});

http://jsfiddle.net/8ZFMJ/398/

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

Generating output into several spans of identical class using JavaScript with compatibility for IE8

Trying to make sense of GetElementsbyClassName function here. My goal is to output the value of an input field, identified by ID, to multiple spans that share a common class on click. I had it working fine with ElementId, but now I need to repeat the user ...

ASP.NET Core Ajax response is empty

function addNewTeam() { var teamName = $("teamField").val(); $.ajax({ type: "POST", url: 'AddNewTeam', contentType: "application/json;", data: { team: "HELLO H ...

Troubleshooting problem: AJAX autocomplete URL returning XML

I found my code reference here: http://example.com/code-reference if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes-> ...

As the div elements stack up and you scroll towards the top or bottom

I am dealing with two nested DIVs that are both scrollable. When I scroll the "inside div" (the green one in the attached file), and reach the bottom of the DIV, it starts scrolling the DIV beneath it. How can I prevent the DIV beneath from scrolling only ...

Create a choppy distortion effect using CSS filters in Google Chrome

Currently working on a hover effect that enhances image brightness and scales the image during hover. However, I am experiencing some choppiness in the transform animation due to the CSS filter. It's strange because it appears to be smooth in Safari a ...

What is the best way to compare the lengths of all nested child elements with each other?

I have an object with nested children, like this: $scope.artists.materials.items[] //contains list of items Now I need to compare the total length of each artist's list of items. If there is a mismatch in the number of items between artists, I want ...

`After compilation, the Material UI component `theme.spacing` was not found in the definition

Currently, I am developing a text editor using Material-UI and draft.js, where the functionality is enclosed in Material-UI components. I have been comfortably working with version ~3.9, but for this specific project, I decided to upgrade to 4.0. Although ...

Retrieving information from a nested .then callback

Summing it up briefly, I've been diving into the depths of learning JavaScript for a while now. After hours and hours of relentless Googling, I find myself stuck with an issue that eludes resolution, pointing to my flawed approach. The objective at h ...

What could be causing the updated JavaScript file to not run on a live Azure website using ASP.NET MVC?

After making a minor adjustment to my JavaScript file on my deployed ASP MVC website hosted on Azure, I decided to redeploy everything. However, upon checking the resource files, I noticed that the JavaScript had indeed been changed, but the behavior of th ...

What is the best way to monitor a document variable that is set after a component has been

Is there a way to access the variable document.googleAnalytics, added by Google Tag Manager, for A/B testing on a Vue.js page? I attempted to initialize the variable in both the mounted and created methods of the component, but it returns as undefined: ex ...

What is the method for showcasing an array using AngularJs in my specific scenario?

I have an array in JavaScript structured like this: var data = [ 2005 = [ Jan = [0,1,2,3,5...], Feb = [0,1,2,3,5...], ...more ], 2006 = [ Jan = [0,1,2,3,5...], Feb = [0,1,2,3,5...], ...more ], 200 ...

Differences in rendering of HTML select element between Chrome on macOS and Chrome on Windows

During testing of a section of the app at my workplace, it was discovered that dropdowns and select elements in a specific UI scenario appeared differently on Chrome for Windows and Ubuntu compared to Chrome for macOS. I attempted to analyze the elements ...

Ways to trigger an alert once a div is fully loaded with content

I have a webpage with a search feature. When the user clicks the search button, the results are fetched via ajax from the database and displayed in a div. After the results are displayed, I want to perform an action as soon as the total count of records i ...

Discovering the 3D coordinates of a point that is perpendicular to the midpoint of a line

(I am working with Javascript/Typescript and Three.js) Given two vectors, let's say {x:1, y:3, z:5} and {x:7, y:8, z:10}, I have a direct straight line connecting them. At the midpoint of this line, envision a disc with a radius of 1 that is perpend ...

Option and Select elements in iOS have unique font sizes

I noticed that the font size of my option is different from my select in Chrome PC compared to IOS. The sizes are exaggerated in the snippet provided. I experimented with and without using optgroup. .styled-select { overflow: hidden; height: 74px; float ...

The jQuery Deferred feature on Ajax is failing to properly pass the array in the data option as an array, instead converting

I am facing an issue in my application where I want to use jQuery deferred to handle Ajax success and error uniformly from a central location. It works perfectly fine when I pass strings in the data option, but when I try to pass an array, it gets sent as ...

Exploring the functionality of Angular directives for bidirectional data binding with object references

In my custom Angular directive (v1.4.3), I am passing two bindings. The first binding is an Object with 2-way binding (model: '=') that can either be an Array or a single Object like [{something: 'foo'}, {something: 'moo'}, ...

What sets apart the usage of <center> from CSS?

Can you explain the key distinctions between using CSS to center an element on a page, as opposed to using HTML tags for the same purpose? How would these different methods impact page layout, compatibility, and other factors? Thank you in advance! ...

What could be causing the error "styled is not defined as a function" while creating my component library using Rollup?

Currently, I am facing an issue with my component library which is built using React, styled-components, framer-motion, Rollup, and Storybook. The library is being consumed by a NextJS website, but when trying to use it, I keep encountering the following e ...

Tips for locating an element within pre-processed HTML content

Is there a way to modify this code snippet to target the 'price' element within each 'info_block' instead of displaying the entire 'info_block' content? My ultimate goal is to locate the price within every 'info_block&apo ...