Reveal the hidden div by sliding it up from the bottom

I have a container with brown branches resembling the image, and I'm looking to hide it. When a button is clicked, I want it to reveal from the bottom to the top, almost like it's being unmasked. I've ruled out a typical bottom-up slide animation due to the presence of leaves at the top, so I'm exploring the idea of unveiling it with a mask effect.

Here's my current setup:

$('.button').click(function () {
        $('#branchmain').show('slide', {direction: 'down'}, 1000);
  });
#branchmain {
    background-image: url(http://i.imgur.com/IV2C28A.png);
    background-repeat: no-repeat;
    display:none;
    width: 114px;
    height: 307px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<div class="button">Click me!</div>
<div id="branchmain"></div>

Is there a way to apply a mask effect to the container and reveal it from bottom to top without actually moving it? I'm looking for a solution to achieve this effect.

https://i.sstatic.net/a140q.png

Answer №1

If you want a smooth effect, try using the 'blind' animation instead of 'slide'.

To display the tree in front of another image, consider using layered divs.

$('.button').click(function () {
        $('#branchmain').show('blind', {direction: 'down'}, 1000);
  });
#branchmain {
    background-image: url(http://i.imgur.com/IV2C28A.png);
    background-repeat: no-repeat;
    display:none;
    width: 114px;
    height: 307px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<div class="button">Click me!</div>
<div id="branchmain"></div>

Answer №2

Utilizing a unique combination of SVG clipping mask and CSS animation, I have successfully created an animation that showcases a fade up effect. It's worth noting that I have set the CSS animation to run indefinitely and made some adjustments specifically for this demonstration. You may want to customize these settings to better suit your needs. However, as a proof of concept, I believe it works exceptionally well:

Snippet of HTML:

<body>
  <img class="clipped" src="http://i.imgur.com/IV2C28A.png" />  
  <svg width="100px" height="400px">
    <defs>
      <clipPath id="clipping">
        <rect width="100" height="300"/>
      </clipPath>
    </defs>
  </svg>
</body>

Snippet of JS:

  img {
    position: absolute;
    top: inherit;
    left: 0;
  }
  img.clipped {
    -webkit-clip-path: url(#clipping);
    z-index: 100;
  }
  div {
    position: absolute;
    left: 410px;
    width: 400px;
    height: 200px;
  }
  div.clipped {
    -webkit-clip-path: url(#clipping);
    z-index: 100;
  /*  opacity: 0;*/
  }
  svg rect {
    animation: move-mask infinite running 4s;
  }
  @keyframes move-mask {
  0%, 100% {transform: translateY(0)}
  50% {transform: translateY(600px)}
  }

Check out the Demo on Codepen:

http://codepen.io/mrwigster/pen/eJNBBK

Answer №3

To create an interesting visual effect, you can overlap one div (which includes a background-image) over another and gradually decrease the max-height of the topmost div:

function shrinkTree() {
var treeWithLeaves = document.getElementsByClassName('tree-with-leaves')[0];
var treeWithoutLeaves = document.getElementsByClassName('tree-without-leaves')[0];
var treeWithLeavesHeight = treeWithoutLeaves.clientHeight;
treeWithLeaves.style.maxHeight = treeWithLeavesHeight + 'px';

var i = 0;

setInterval(function(){
treeWithLeaves.style.maxHeight = (treeWithLeavesHeight - i) + 'px';
i++;
},20);
}

document.getElementsByTagName('button')[0].addEventListener('click',shrinkTree,false);
body {
margin: 25px 0 0 50px;
}

.tree-with-leaves, .tree-without-leaves {
width: 125px;
height: 236px;
}

.tree-with-leaves {
background-image: url('https://i.sstatic.net/a140q.png');
}

.tree-without-leaves  {
background-image: url('http://i.imgur.com/IV2C28A.png');
background-color: rgb(255,255,255);
overflow: hidden;
}

button {
display: block;
margin: 25px;
}
<div class="tree-without-leaves">
<div class="tree-with-leaves">
</div>
</div>

<button>Click Me</button>

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

What could be causing my Puppeteer scraper to malfunction when I alter the search term?

The Task In this project, I am building a web scraper using NodeJS with Puppeteer. The goal is to scrape data for "Jeep Wranglers" and organize the results in JSON format. Comparing IPhone X and Jeep Wrangler Initially, everything worked smooth ...

Sanitize input data prior to using express-validator in a Node.js application

In my Node.js project, I am utilizing the V4 syntax of express-validator as recommended: const { check, validationResult } = require('express-validator/check'); const { matchedData } = require('express-validator/filter'); Additionally ...

What is the best way to implement my custom toolbar button to utilize the form's validation function within react-admin?

I have developed a unique Toolbar with a custom button that is supposed to mimic the behavior of the standard SaveButton but also perform additional actions after the form is submitted. The form should only be able to submit if it passes validation, and an ...

Sending a file through an Ajax POST request to a PHP server

I am attempting to upload the HTML input file to my PHP file using a different method than the traditional synchronous HTML forms. The problem I am encountering is that it seems like I am not correctly POST'ing the input file to my PHP file because t ...

Challenges with optimization in AngularJS and Angular Material

Currently, I am working on an AngularJS application that utilizes 7 Angular Material tabs. One issue I have encountered is a significant amount of animation lag when switching tabs or opening a md-select element. According to Chrome Developer Tools, the fr ...

Spread the picture on social media using Progressive Web App

I am currently working on a Nuxt PWA where I have implemented a function to convert HTML to Canvas using a specific package. The output generated is in base 64 format. My goal now is to find a way to easily share this image through various platforms such a ...

Toggle the visibility of a specific div based on the selection of the "other" radio button or checkbox

While my question may not be vastly different from others that have been asked before, it's the subtle nuances that are causing me some trouble. In essence, I am trying to toggle the visibility of a text input field used for specifying the "other" op ...

Use the Arrow Keys to guide your way through the Page

I am looking to enhance user experience by allowing them to easily navigate through my webpage using the arrow keys on their keyboard. The goal is for users to be able to move from one section to the next in a seamless manner, unless they are focused on an ...

Incorporating a Bootstrap form within a form group

Can a select element be inserted inside a horizontal form in Bootstrap? I am trying to add a form with a select element inside a form group. Check out the code on Bootply. Note: Copy the code below as Bootply sometimes removes certain form tags. The is ...

React.js Component Composition Problem

I am attempting to replicate the following straightforward HTML code within a React environment: Traditional HTML <div> Hello <div>child</div> <div>child</div> <div>child</div> </div> React(working ...

The functionality of both P and H1 tags seems to be malfunctioning

Can someone help me with changing the font family and size of my paragraphs and headings (p and h1)? Any assistance would be greatly appreciated. Feel free to review my code for any other errors as it has been a while since I last coded. html, body { ma ...

How come I can't see this on my display?

I'm facing an issue with this particular HTML snippet not displaying when I view the file in Chrome or any other browser. Below is the code: <!DOCTYPE html> <html> <head> <title> # <title& ...

Issues with uploading files in NodeJs using express-fileupload are causing errors

I created a REST API in NodeJs for File Upload which is functioning correctly, however I am facing an issue. When I upload more than 2 images, only 2 or 3 get uploaded and sometimes one gets corrupted. I suspect that the loop is running too fast causing th ...

What steps should I take in order to ensure that NPM commands run smoothly within Eclipse?

I have a functional workflow that I'm looking to enhance. Currently, I am developing a JavaScript library and conducting smoke tests on the code by using webpack to bundle the library and save it to a file that can be included in an HTML file for test ...

The elements of the second flex item should also be arranged in a line next to each other

<script src="https://use.fontawesome.com/2a2c577e07.js"></script> <div class="parent-flex"> <div class="class1">Class 1</div> <div class="class2"> <img src="http://farm4.static.flickr.com/3140/3506456511_43787 ...

Use a text link to upload a file instead of using an input field

While I've seen some discussions on this topic already, the conflicting answers have left me uncertain. Is there a foolproof method for triggering file upload without using an input field? Essentially, I'd like to create a div with an icon and te ...

Using logical equality operators in Javascript

Imagine I have two boolean variables and I need to determine when they are both true or false, essentially requiring a logical equality operator.' Most JavaScript resources recommend using bitwise operators, with the XOR operator performing a similar ...

Steps to transfer text from one input field to another by clicking a button using JavaScript

Hello, I am new to Javascript so please forgive me if my question seems silly. I have been tasked with creating a form containing two input fields and a button. When the button is clicked, the text entered in the first field should move to the second field ...

D3 - Rounded edge chart width

Currently facing an issue with the chart where the data value is small, resulting in an 'ear' effect. Can anyone help me with this problem? Below is the code I am currently using: const rx = 30; const ry = 30; svg ...

Retrieve a subsection of an object array based on a specified condition

How can I extract names from this dataset where the status is marked as completed? I have retrieved this information from an API and I need to store the names in a state specifically for those with a completed status. "data": [ { "st ...