Ensure that the div's overflow extends halfway beyond the top of its parent element

I want to create a stylish bottom drawer slider that features a unique circular button fixed at the bottom of the page. When the drawer is closed, only half of the button should be visible (half a circle), and clicking on it will expand the drawer.

Here's a basic representation:


      _____________________________
      |         Web Page          |
      |                           | 
      |                           |
      |           ____            |
      |__________/ /\ \___________|  < Closed (bottom of browser window)

      _____________________________
      |         Web Page          | 
      |           ____            |
      |__________/ /\ \___________|  < Opened
      |          \____/           |
      |___________________________|
    

For code demonstration, check out this JsFiddle link: https://jsfiddle.net/ppgab/wcec9gc6/4/ (Note: Semantic UI may not be necessary).

The goal is to show only one half of the button when the drawer is closed.

HTML

<div>Page content</div>
    <div id="map" class="down">
      <div>
        <i class="ui circular link expand big inverted icon"></i>
      </div>
      bottom slider content
    </div>
    

CSS

#map {
      background-color: #303030;
      width: 100%;
      text-align: center !important;
      height: 4%;
      bottom: 0;
      position: fixed;
    }
    

JavaScript/jQuery

$('.icon').click(function() {

      if ($("#map").hasClass("down")) {
        $("#map").removeClass("down");
        $("#map").animate({
          height: "50%"
        }, 600);

      } else {

        $("#map").animate({
          height: "4%"
        }, 350);
        $("#map").addClass("down");
      }

    });
    

It would be ideal to use percentage dimensions for better responsiveness.

Answer №1

To achieve the desired visual effect, I implemented three modifications:

1. Adjusted the position of the icon

To move the icon upwards, I applied a simple margin-top: 28px to position it halfway up (considering its total height and padding of 56px) or utilized transform: translateY(-50%) for an alternative solution.

2. Removed transparency from the icon

The transparency issue was due to an overflow: hidden in the #map element triggered by the animate() jQuery function. Adding overflow: visible to the #map element resolved this problem.

3. Completely concealed the #map

To hide the #map completely, I adjusted the height property to 0 in both the CSS and JS sections.


In brief:

$('.icon').click(function() {

  if ($("#map").hasClass("down")) {
    $("#map").removeClass("down");
    $("#map").animate({
      height: "50%"
    }, 600);

  } else {

    $("#map").animate({
      height: "0%"
    }, 350);
    $("#map").addClass("down");
  }

});
#map {
  background: #303030;
  width: 100%;
  text-align: center !important;
  height: 0;
  bottom: 0;
  position: fixed;
  overflow: visible !important;
}
i {
  margin-top: -28px;
  transform: translateY(-50%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Page content</div>

<div id="map" class="down">
  <div>
    <i class="ui circular link expand big inverted icon"></i>
  </div>
  bottom slider content
</div>

See the working Demo: JSFiddle

Answer №2

Check out this code snippet where I removed the icon and modified the background color.

$('#circle').click(function() {

  if ($("#map").hasClass("down")) {
    $("#map").removeClass("down");
    $("#map").animate({
      height: "50%"
    }, 600);

  } else {

    $("#map").animate({
      height: "0%"
    }, 350);
    $("#map").addClass("down");
  }

});
#map {
  overflow: visible !important;
  background: #303030;
  width: 100%;
  text-align: center !important;
  height: 0%;
  bottom: 0;
  position: fixed;
  color: #fff;
}

#circle {
  background-color: #303030;
  height: 70px;
  width: 70px;
  border-radius: 35px;
  margin: -35px auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Page content</div>

<div id="map" class="down">
  <div>
      <div id="circle">
      
      </div>
  </div>
  Additional slider content at the bottom
</div>

Answer №3

Make sure to position your .icon element absolutely within the boundaries of your #map div

CSS

.icon {
    position:absolute;
        top:0;
        left:50%;
    transform: translate(-50%, -50%);
}

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: Issue with Angular ng-click functionality not

I'm struggling with the code below: <div class="row"> <div ng-repeat="stat in stats"> <div class="col-lg-3 col-md-6 col-sm-6" ng-click="hideShow=(hideShow ? false : true); vm.charts(stat.jobId)"> <div cla ...

There seems to be confusion surrounding the $.isArray() function in jQuery

I'm currently trying to determine whether the p array is valid or not. I'm not sure if I'm on the right track or if I'm making a mistake. I am currently studying the jQuery.isArray method. I suspect that there may be an error in my code ...

The jQuery attribute selector seems to be malfunctioning when targeting data attributes

Although this question may resemble others on SO like Selecting element by data attribute and jQuery how to find an element based on a data-attribute value?, I am still struggling to select all elements where the attribute "data-value" exists. The Issue ...

Troubleshooting issues in Safari's Web Inspector while utilizing a module loader such as SystemJS

I am currently developing an Angular application using es6 modules, TypeScript, and SystemJS as the module loader. This is my current configuration: tsconfig.json: { "compilerOptions": { ... "target": "es5", "module": "system", ... } ...

Is there a way to trigger Material-UI SpeedDialAction onClick events only when the SpeedDial is open and clicked, not when it is hovered over?

After making a modification to material-ui's <SpeedDial> component by removing the onMouseEnter={handleOpen} prop, I noticed that the onClick event within the <SpeedDialAction> component no longer triggers when clicking on a menu item. It ...

Mastering the art of completing a form using AJAX

I'm working on a checkbox that triggers AJAX to create a new log. It populates the necessary information and automatically clicks the "create" button. However, I'm facing an issue where the hour value is not changing. Any help on what I might be ...

Challenge encountered with Promise failing to resolve despite multiple retry attempts

I've been struggling with Promises as a beginner for the past few days. I need to make an API call and check if there is a response. If not, I have to retry calling the API a configurable number of times. I attempted the following code, but I'm u ...

Utilize the client's IP address as a cookie in order to recognize return visits and showcase a special message following the initial visit

First of all, a big thank you to anyone who can help resolve this issue. I apologize if this has been asked before (I couldn't find it anywhere, so I decided to post a new question). The main problem I am facing is getting my webpage to show an alert ...

Unable to retrieve the ZIP archive generated dynamically

I am facing an issue while attempting to generate a dynamic output from MySQL queries and create an archive. Below is the code snippet I have been working with: var async = require("async"); var mysql = require("mysql"); var express = require("express"); ...

Is assigning key value pairs a statement in JavaScript?

I am curious to learn about the following code snippet: var a = {x:function(){},y:function(){}} Can we consider x:function(){} to be a statement within this code? ...

Visualization of pie charts in Angular2 using Google library

Currently, I am in the process of building a web application using Angular2 that includes a Google pie chart. One of the components of the application is a Directive specifically designed for the pie chart. Below is the code snippet for the Directive: @D ...

Is there anyone who is able to provide an answer to this question

Can anyone help me with connecting a Python program to HTML? I want the output from the Python program to be displayed on the front end when an HTML button is clicked. Any guidance on how to solve this issue would be greatly appreciated. I'm looking t ...

The functionality of getAttribute has changed in Firefox 3.5 and IE8, no longer behaving as it did before

Creating a JavaScript function to locate an anchor in a page (specifically with, not an id) and then going through its parent elements until finding one that contains a specified class. The code below works perfectly in Firefox 3.0 but encounters issues wi ...

Java Entity Framework Indexing Tables

I am currently utilizing ASP.Net Core and have implemented EntityFramework to create a controller with views. Specifically, I am in the process of enhancing the Index view to make it dynamic with dropdown selections. I have successfully completed everythin ...

Executing a JavaScript function by utilizing the # symbol in the URL: Tips and Tricks

It all began with a function called loadround that changed the innerHTML of an iframe. The links within the iframe would then change the page when clicked, but hitting the back button made the loadround page vanish. I pondered over this issue multiple time ...

Using CSS for layout positioning

This problem has been confounding me for quite some time now, even though the solution is likely very simple. I can't seem to figure out how to align two divs of different sizes side by side without one being pushed down a few lines when text is added ...

Ensure that the dropdown menu remains at the forefront of all other elements

I am facing an issue with a dropdown menu that changes the language. The problem occurs when the list of languages gets longer and the menu ends up behind other elements on the page. I'm not sure what needs to be changed or which CSS properties I nee ...

Guide to accessing Google Map tag in a JavaScript document

I've been working on ASP.Net MVC and we have incorporated an external .JS file to store all our JavaScript code. Initially, I included the Google Map code directly in the View, and it was functioning perfectly, displaying the map as expected. However, ...

Exploring the Overlapping of Objects in Three.js

I am dealing with multiple meshes in my code and I am trying to figure out how to make the renderer display the object that should be in front, somewhat similar to what is shown in this example: --> . I have read about render depth, but I am unsure of h ...

What's the best way to unpack the gzip data that Ajax sends to JavaScript?

Hello there! I've encountered an issue: PHP is sending compressed data using gzdeflate(): $string=gzdeflate($string,9); echo $string; In the browser, pako.js has been included and the following code is executed: var rsp=rst.responseText; rsp=pako.in ...