Move the upper div to the lower section once the lower div vanishes from view

In the current setup, .div1 is positioned 50px above the bottom of the video frame. My goal is to make it so that when .div2 (the controls bar) disappears, .div1 smoothly moves down and sticks to the new bottom position.

I envision this functionality similar to how Netflix's video player handles subtitles - when the controls bar vanishes, the subtitles should gracefully slide down to the bottom of the screen. This is the effect I want to achieve. Test

body {
  background-color: gray;
  margin: 0 auto;
}
.out {
  width: 1000px;
  position: relative;
  height: 560px;
  background-color: #000;
  left: 50%;
  margin-left: -500px;
  top: 50%;
  margin-top: -280px;
}
.div1 {
  width: 100%;
  height: 50px;
  background-color: red;
  position: absolute;
  bottom: 50px;
}
.div2 {
  width: 100%;
  height: 50px;
  background-color: blue;
  position: absolute;
  bottom: 0;
}
<div class="out">
  <div class="div1"></div>
  <div class="div2"></div>
</div>

Answer №1

To adjust the positioning of the blue div, simply toggle its visibility and change the css bottom property accordingly. I've included a button to trigger this action, but feel free to use any other method (such as hovering over an element or clicking on something else).

var flip = 0;
$('#btnChange').on('click',function(){
    $('.div2').toggle(0,function(){
        if(flip++ % 2 === 0){
            $('.div1').css("bottom", "0px");
        } else{
            $('.div1').css("bottom", "50px");
        }
    });
});

http://jsfiddle.net/acsvrzLf/

Answer №2

If using jQuery, the following code should accomplish the task:

$(".out").find(".div2").hide().end().find(".div1").css({"bottom": "0px"});

This snippet is effective on your test page after including jQuery.

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

Functions perfectly in jsFiddle, however does not function as intended on my personal website

I am experiencing a strange issue with the jQuery code on my website. Surprisingly, the code works perfectly fine on jsFiddle but not when I run it locally. Both instances have the exact same code as I simply copied and pasted it. Can anyone provide insi ...

The middle toggle line stubbornly refuses to properly disappear

I'm facing an issue with the toggle button on my practice site. When clicked, it undergoes a transition and displays a cross or X symbol. I've used CSS to create a cross shape by hiding the middle line. However, after the transition, the middle l ...

Using Various Buttons in a Bootstrap Form

I have implemented Bootstrap to create a form. The form structure is as follows: <form action="default_results.php" method="post" class="calculator" name="frmCalculator"> At the beginning of my code, I used the above form code. At the end of the pa ...

showcasing a picture retrieved from an express server

Struggling to incorporate an image from an api into an img tag, unsure of the data type and how to process it for display. The data remains consistent regardless of using pipe() or res.sendFile(). Witness the server in action: app.get('/image', ...

Issues with footers in IE 10/11 and Edge when using Grid layout

In the latest versions of Chrome, Firefox, Opera, IE 10/11 and Edge, the Grid layout below works perfectly fine. The only issue is with the Microsoft browsers where the footer fails to start scrolling when the content exceeds the screen size, leaving it fi ...

Ensure that all panels are set to the same width as the widest panel

Is there a way to make all the panels in my jQuery tabs have the same width as the widest panel? I know that heightStyle:"auto" works for adjusting the height, but is there a similar option like widthStyle:"auto"? I want to show you the current look compa ...

Search and Swap content on Page using jQuery Array

Seeking help with a find and replace operation using jQuery on an array of characters. The original array consists of the following symbols: var f = ['“','â€','‘'','’','…', ...

My search field in Safari (desktop) doesn't respond to jQuery's .focus() function

My website has a hidden search field that appears when the user clicks on the search icon. I want to automatically bring focus to the search input so users do not have to click twice. This feature works perfectly in Chrome, but not in Safari (desktop). I t ...

Link that causes the regular expression test to hang

My goal is to create a regular expression that can accurately identify URLs. I found the code snippet for this on Check if a Javascript string is a url. The code looks like this: function ValidURL(str) { var pattern = new RegExp('^(https?:\/&b ...

What could be causing WebKit to fail in accurately redrawing this text?

I am experiencing a unique issue with the WebKit renderer. It seems that when a text node contains a descender or ascender that extends beyond the selection box of the text node, and the position of the text node changes, WebKit fails to repaint the correc ...

Unequal height among each div's elements

I'm struggling with creating a footer divided into 3 blocks, but they do not have equal heights, causing the border-right line to appear uneven. Here is a screenshot of the issue: Not equal height of elements Any suggestions on how to fix this? Is m ...

Improperly positioned Divs overlapping

Help needed: I am attempting to add a menu to a specific section. The menu div is extending off the page to the right, but it should be contained within the HOMEMENU section (the long black bar with no content). Despite using a clear:both div, the menu s ...

Harness the power of electrons with the simple push of a button - initiating program execution

Recently, I delved into Electron with the desire to create a small application for myself. This app would allow me to run different programs or games by simply clicking on a link. My goal is to have the program/game start automatically when I open the Ele ...

Problem encountered with ASP.NET jQuery C# MessageBox.Show dialog...Uh oh!

Managing an ASP.NET site, I decided to enhance the appearance of the dialogs using jQuery. The web application includes a C# class named MessageBox that facilitates displaying messages to the client from the server side. Essentially, within the C# on an as ...

Tips for minimizing the size of this script

I am new to using Jquery and Javascript, but I have managed to create a script that communicates with a php controller in symfony2. My query is, how can I shorten the script length? Is there a more efficient way to solve the logic instead of using the swi ...

Adding a border to my image that extends to the edges of the page

.overlay{ position:absolute; top:0; left:0; height:100%; width:100%; background:url(hex-shape.png) no-repeat center; z-index:99999; } I have created an overlay background image that covers the entire page. I want the area surrounding the ove ...

I am in the process of extracting information from the database, but I encountered an error stating that the variable $request is undefined

My controller contains a method called request, which retrieves data from the database and then compacts the variable with the view. <?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use ...

Creating a mask overlay that covers the entire screen while excluding a specific sibling div

My goal is to create a div that acts as a mask covering the entire window. It should have an opacity of 0.5 and a background color of lightgray. However, there is one particular div on the screen that I do not want to be affected by the mask. I attempted t ...

What steps can be taken to stop Internet Explorer from interfering with a hover trigger on a child element?

I'm encountering an issue with my HTML and CSS code that seems to work perfectly in all browsers except for IE10 and below. The problem arises on a user profile page where there is a profile picture (avatar). When hovering over the avatar, the CSS tr ...

What is the best way to generate a dynamic div element filled with data?

When using inner HTML to dynamically retrieve divs with SQL Server data, I am encountering an issue where the div arrangement is not aligning horizontally. I need assistance in aligning them horizontally. Thank you. pnl_default.Visible = true; ...