I would like to know how to create an animated effect where an Element slides into view when a user selects an option from a drop-down menu

Is there a way to make an element on my page slide in automatically after 3 seconds when the page is opened, and then slide out once the user selects their desired choice from a dropdown menu (which is the Element)? I would like the sliding effect to come from the right-hand side of the page.

The specific dropdown menu in question is the 'Google Translate Element', which has been customized to fit my design preferences. I'd like this element to slide in 4 seconds after the page loads and then slide out after the user has chosen their preferred language.

Here is the code for the styled Element:

 /*google translate Dropdown */
#google_translate_element select{
 background: rgba(246,237,253,0.92) !important;
 border: none !important;
 color: rgba(54,58,173) !important;
 width: 115px !important;
 border-radius: 5px !important;
 padding: 5px 5px !important;
 font-size: 11.8px !important;
 position: absolute !important; 
 margin-top: 84px !important; 
 margin-left: 232px !important;
}
.vl {
    position: absolute !important;
    border-left: 3.7px solid green !important;
    border-radius: 2px !important;
    height: 30px !important;
    margin-top: 67px !important;
    margin-left:351px !important;
}
 /*google translate link | logo */
.goog-logo-link,.goog-te-gadget span,div#goog-gt-{
   display:none!important;
}
.goog-te-gadget{
   color:transparent!important;
   font-size:0;
 }
 /* google translate banner-frame */
.goog-te-banner-frame{
 display:none !important;
 }
#goog-gt-tt, .goog-te-balloon-frame{
   display: none !important;
}
.goog-text-highlight { 
    background: none !important; 
    box-shadow: none !important;
}
<div id="google_translate_element"></div>
<div class="vl"></div>

Answer №1

If you want to conceal the element on the right side, try these methods:

  1. Adjust the css property right to a value less than zero and set its position as absolute. This will hide the element towards the right edge of the page. Remember to specify position:absolute, and the extent to which it is hidden by the right property depends on the width of the element. If the width is 2 px, avoid setting right to 50px; experiment until you achieve the desired result.

To make it visible again:

  1. Modify the right css property to 0 or a higher value using this link; this action will bring it back onto the page.

If you wish to reveal it after a certain number of seconds following user selection:

  1. Add an event listener to each selectable item in the dropdown (either individually or from its parent element), typically through an onclick listener.
  2. Once the event is triggered, employ a setTimeout function with JS (link) for your preferred duration, along with a callback to a function that adjusts the hidden element's right property to a value greater than 0, thus bringing it into view from the right side.

The process could resemble the following snippet:

/*css*/
element {
  right: -15px;
}
/*js to show after 4 seconds*/
const showElement = () => {
  /*update css `right` property*/ 
}

let startTimeout = setTimeout(showElement(), 4000)

element.addEventListener('click', startTimeout())

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

Forcing a property binding update in Angular 2

Take a look at this particular component import {Component} from 'angular2/core' @Component({ selector: 'my-app', providers: [], template: ` <div> <h3>Input with two decimals</h3> <input type ...

Generating various fields within a single row

I am in the process of creating a dynamic form that should generate two new fields in the same line when the user clicks on the plus icon. Currently, the code I have only creates a single field. I attempted to duplicate the code within the function, but i ...

Unable to align text within a DIV using CSS

Recently, I started learning jQuery and building my own website. You can find my project on JSFIDDLE. The issue I'm facing is that when hovering over a new div, the text extends beyond the borders of that div instead of staying within it. I've sp ...

An error has occurred in the Shadow Dom due to the inability to access the property 'style' of an

While working on a component using shadow DOM, I encountered the following error in the console: "Cannot read property 'style' of undefined". This issue seems to be related to my HTML code in PHP. The main challenge I am facing is figuring out ho ...

Pass data from Action Class to ajax using JSON syntax

Currently I am facing an issue while working on fullCalendar, a jQuery plugin. I am trying to populate event details from a database when the Calendar page loads, but I seem to be stuck with a silly problem that I can't figure out. $('#calendar& ...

Issues with implementing a Bootstrap dropdown list in a Django HTML template

I'm having trouble implementing Bootstrap in my Django project's shared HTML file. The dropdown list isn't functioning properly despite trying various approaches, including using CDN and local Bootstrap files. When I click on the dropdown li ...

Minimize the visibility of the variable on a larger scale

I have a nodejs app where I define global variables shared across multiple files. For example: //common.js async = requires("async"); isAuthenticated = function() { //... return false; }; //run.js require("common.js"); async.series([function () { i ...

Creating a foundational design with Bootstrap 5, featuring a sidebar that scrolls seamlessly and a stunning fixed

I'm having some trouble figuring out the layout for a webapp I want to develop. LAYOUT IMAGE What I envision is a sidebar menu on the "S" section that can be scrolled independently, and a large image on the "I" section that changes based on th ...

React Bootstrap encountered rendering issues

Recently, I decided to delve into the world of React Bootstrap and started my learning journey. To get started, I followed some tutorials on <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <meta name="vi ...

What is the reason behind causing the overflow to become visible on the parent anchor when a child anchor is added?

I've been facing a puzzling issue for the past day. I am working on creating a website that resembles Windows 8, where each box represents a list item. The code is more complex than what I have shared here, but the problem seems to be isolated... &l ...

Cross-browser compatibility issues preventing CSS button effects from functioning properly

Experiencing some challenges with CSS Button effects not functioning consistently across different browsers. The display is satisfactory in Chrome, but not in Firefox. Struggling to pinpoint the source of the issue. Here is my current setup: Fiddle a ...

Querying MongoDB findAndModify: <<< locate and modify an object within an array in a document

Question : I am attempting to locate an object within a document's array and make updates to it. The syntax below provides me with the desired object, but I am unsure of how to update it. I attempted to use this query in findAndModify, but it seems ...

What is the best way to create a fading footer effect on scroll using jQuery?

Why is my footer not fading in after 1000px like I want it to? Instead, it appears immediately on the screen. I attempted using fadeIn() in jQuery but had no luck. I also tried to make it disappear with fadeOut(), again with no success. Am I missing someth ...

Switch the CSS class with an HTML tag

Can someone help me transform this code snippet with Python 3 and Beautiful Soup? <span class="ld-nowrap"> 20th century’s </span> I need to convert it to: <em> 20th century’s </em> Any suggestions on how to achieve t ...

Oops! Looks like we have encountered an issue in three.js: The constructor for Materials[json.type]

I've been developing a web application that displays 3D animated models created in 'Maya 2016'. These models are exported using the three.js (r81) 'maya exporter plugin'. For those interested, you can find the maya exporter plugin ...

Encountered an ERR_SOCKET_TIMEOUT when trying to install React.js

When attempting to install React using npx create-react-app, an error occurred: npm ERR! errno ERR_SOCKET_TIMEOUT npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/cosmiconfig: Socket timeout npm ERR! network This issu ...

Tips for setting the height of a div within a td to be 100%

I am struggling to make the orange divs in this example stretch out to match the height of the enclosing td element without explicitly setting the parent's height. I have tried using display: flex and align-items: stretch, but I can't seem to ach ...

Navigating through the Roots in ICanHaz.js / Mustache

I'm encountering a problem with iterating using ICanHaz.js / Mustache. My goal is to iterate over the roots of a JSON structure and extract a specific parameter. This is the JSON I'm working with: { "1": { "param1": "true", "param2": "fa ...

Sorting columns using custom conditions in DataTables

Within a PHP project I am working on, I have encountered a need to organize a specific column using a custom condition or order rather than relying on the default ordering provided by DataTable (ascending or descending). The project involves four distinct ...

Decrease the amount of empty space when adjusting the window size

Struggling to make a section of my website responsive and encountering an issue that's proving difficult to solve. The current setup involves 3 rectangular inline-block divs per "row" with a margin-right of 100px in a wrapper, all dynamically added. ...