Make sure to have a ".hover" animated component remain visible on the screen even after transitioning to it from a trigger

Hopefully, my title wasn't too lengthy. This is my first question, so please be patient with me.

I have a group of divs inside my .navicons div that I want to use as triggers for offscreen elements (#wdFoot, #wpFoot, #gdFoot) to move up into view from the bottom of the screen when hovered over. I've managed to achieve this effect using .hover and .animate, but for better usability, I would like the animated footer elements to remain raised on the screen even when the user moves their mouse from the trigger area to the raised foot elements.

Here's what I currently have:

<div class="navicons">
    <div id="wdicon"><!-- triggering divs  -->
        Wd
    </div>
    <div id="wpicon">
        Wp
    </div>
    <div id="gdicon">
        Gd
    </div>
</div>

<section id="wdFoot" class="footNav"><!-- once they appear on screen, I want these to stay visible when the user moves the mouse from the triggers to this area  -->
    <h2>Wd Foot</h2>
</section>

<section id="wpFoot" class="footNav">
    <h2>Wp Foot</h2>
</section>

<section id="gdFoot" class="footNav">
    <h2>Gd Foot</h2>
</section>

CSS//

body{
    overflow:hidden;
}
div.navicons{
    width:auto;
    position:absolute;
    margin:0 auto;
  }
.navicons > div{
    width:80px;
    height:80px;
    border:2px solid rgba(178,178,178,.08);
    border-radius:50%;
    text-align:center;
    display:inline-block;
    transition:all .05s;
}
.navicons > div:hover{
    border:2px solid #1f88e1;
}
section.footNav{
  width:100%;
  height:240px;
  background-color:rgba(51,51,51,.7);
  position:absolute;
  bottom:-240px;
}

jQuery//

$( '#wdicon' ).hover(function() {
     $( "#wdFoot" ).animate({'bottom':'0'}, 500);
  },function(){
     $("#wdFoot").animate({'bottom':'-240px'}, 500);
  });

$( '#wpicon' ).hover(function() {
     $( "#wpFoot" ).animate({'bottom':'0'}, 500);
  },function(){
     $("#wpFoot").animate({'bottom':'-240px'}, 500);
  });

$( '#gdicon' ).hover(function() {
     $( "#gdFoot" ).animate({'bottom':'0'}, 500);
  },function(){
     $("#gdFoot").animate({'bottom':'-240px'}, 500);
  });

Check out the JSFiddle link for a demo.

If you know of an easier or shorter way to write my jQuery code, please share it with me.

Thank you!

Answer №1

Consider this option for handling footer removal based on user actions. The approach outlined here ensures that the footer remains visible for a specified duration before being dismissed. By utilizing the setTimeout function and a data attribute, you can achieve this functionality efficiently.

To implement this solution, begin by setting up the necessary HTML structure with data attributes to streamline the hover interactions:

<div class="navicons">
    <div id="wdicon" data-hover="wdFoot">
        Wd
    </div>
    <div id="wpicon" data-hover="wpFoot">
        Wp
    </div>
    <div id="gdicon" data-hover="gdFoot">
        Gd
    </div>
</div>

<section id="wdFoot" class="footNav">
    <h2>Wd Foot</h2>
</section>

<section id="wpFoot" class="footNav">
    <h2>Wp Foot</h2>
</section>

<section id="gdFoot" class="footNav">
    <h2>Gd Foot</h2>
</section>

The next step involves using JavaScript to handle the timing of the dismissal animation after a specified delay:

var dismissTimeout;

var dismiss = function($group) {
    $group.animate({'bottom':'-240px'}, 500);
};

$( '[data-hover]' ).hover(function() {
    $(".footNav").stop().css('bottom': '-240px');
    $( "#" + $(this).data("hover") ).stop().animate({'bottom':'0'}, 500);
},function(){
    dismissTimeout = setTimeout(function() {
        dismiss($("#" + $(this).data("hover") ));
    }.bind(this), 1000);
});

Ensure to clear the dismissTimeout variable within the hover event handlers on the footer elements:

$('.footNav').hover(function() {
    clearTimeout(dismissTimeout);
}, function() {
    dismiss($(this));
});

You can view a working example in my version of the fiddle here. Feel free to experiment with different animations and transitions for enhanced user experience by referencing the provided examples.

Answer №2

After reviewing the initial question, I quickly put together this code snippet.

$( '#wdicon' ).hover(function() {
    $( "#wdFoot" ).stop().animate({'bottom':'0'}, 500);
    $("#gdFoot, #wpFoot").stop().animate({'bottom':'-240px'}, 500);
});

$( '#wpicon' ).hover(function() {
  $( "#wpFoot" ).stop().animate({'bottom':'0'}, 500);
  $("#wdFoot, #gdFoot").stop().animate({'bottom':'-240px'}, 500);
});

$( '#gdicon' ).hover(function() {
  $( "#gdFoot" ).stop().animate({'bottom':'0'}, 500);
  $("#wdFoot, #wpFoot").stop().animate({'bottom':'-240px'}, 500);
});

https://jsfiddle.net/aegmqfjx/

The concept here is that when hovering over one button, it triggers the hiding of other footers while sliding up the footer for your specific button.

It's important to incorporate .stop or a similar method to prevent animations from accumulating if a user rapidly hovers over the buttons.

Answer №3

It is important to use .stop() to prevent animation buildups during fast mouse movements. A more concise approach to achieve the same effect is here:

$(".navicons [id$=icon]").hover(function( e ) {
    var pr = this.id.split("icon")[0];   // extract ID prefix
    var mE = e.type==="mouseenter";      // check if mouseenter event
    $("#"+ pr +"Foot" ).stop().animate({bottom: mE ? 0 : -240}, 500);
});

If you want to keep the element open when hovered, a simple hover may not be sufficient, and utilizing a timeout is necessary (as per your clarification needs).

Since no timeout was requested:

I wish for the animated footer elements to stay elevated or within view when the user transitions their mouse from the trigger area to the raised foot elements

Check out the jsfiddle demo here:

var $activeFoot,

$(".navicons > div").add( $activeFoot ).hover(function( e ) {
    // If there's an active element, stop its animation
    if($activeFoot) $activeFoot.stop().animate({bottom: -240}, 500); 
    // Set the current element as active
    $activeFoot = $("#"+ this.id.split("icon")[0] +"Foot");
    // Animate in the active element
    $activeFoot.stop().animate({bottom: 0}, 500); 
});

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

"The Vue.js/JavaScript object updates, but the changes are not being displayed in the document object model (DOM

Currently, I am endeavoring to iterate through an array of objects and display them as list items. There is a click listener that introduces a custom property to the object, and a class binding depends on the value of that property. Would you mind reviewin ...

Ways to avoid Next.js from creating a singleton class/object multiple times

I developed a unique analytics tool that looks like this: class Analytics { data: Record<string, IData>; constructor() { this.data = {}; } setPaths(identifier: string) { if (!this.data[identifier]) this.da ...

Persisting old select dropdown choices after failed validation with Ajax in Laravel

Within my create view, I have a dependent dropdown for "Category" and "Subcategory" that is functioning correctly. However, when certain validations fail, the selections are not restored to their previous state. Create View: <div> <label for= ...

Converting PHP arrays into visually appealing HTML tables

Having trouble writing a code to generate a table using the provided PHP array named $associative_array1 array( 'Objective' => array(0 => 'Conversions', 1 => 'Lead Generation', ), 'Gender' => array(0 =&g ...

Developing a project similar to the one designed for three.js

I'm excited about recreating something similar to the example in this video: http://www.youtube.com/watch?v=gYGzsM4snmg. Can anyone provide guidance on where to find the source code or offer a beginner-friendly explanation, considering I am new to thr ...

What is the best way to add animation to the border-style using jQuery?

I've successfully animated the border-color and border-width using borderColor and borderWidth, but I'm now curious about animating the border style with borderStyle. Unfortunately, my searches so far have been unsuccessful. Is there a way to ani ...

What is the correct way to align my checkboxes with their corresponding labels?

I have been working with HTML to make some adjustments to a website. I recently got feedback to change the label of my checkbox, however, it is now overlapping with another checkbox. How can I resolve this issue? ...

Navigate to a different page in NextJs and initiate a smooth scrolling effect using the react-scroll library

Utilizing the Next.js Link element in my React application: import Link from 'next/link'; Along with buttons that scroll to a specific element when clicked using: import { Link } from 'react-scroll'; https://www.npmjs.com/package/reac ...

The intricate Q pledge: the assurance of one promise generating a series of other promises

I am facing an http request that is expected to provide a list of tasks, but the process of generating these tasks is quite intricate. Here is a breakdown of how it operates: Retrieve all existing tasks from the database Identify and expire any outdated ...

Inspect all checkboxes created by JavaScript

I'm attempting to develop a checkall checkbox that will automatically select all the checkboxes I've created using JavaScript. Firstly, I gather the number of rows and columns from the user and then use JavaScript to generate a table and insert ...

Mapping an array to another array using AngularJS

I am working with two arrays - Users and Employments. Here is how they are structured: Users = [{id:1, name: "ryan"}, {id:2, name:"Julie"}] Employments = [{user_id: 1, title: "manager"}, {user_id: 2, title: "Professor"}] My goal is to display the E ...

New replacement for routerState.parent feature that has been deprecated in angular2

During my work with Angular 2 rc5, I encountered the following code snippet. this.router.routerState.parent(this.route).params.forEach((params: Params) => { url = params['url']; id = +params['id']; }); I had to resort to th ...

Converting a MySQL date field into a specific format using PHP

Similar Question: PHP convert one date into another date format I am looking to convert the date 2011-09-06 to a format like 2011-09-06T00:00:00.0000000 I searched online but couldn't find a clear solution. Your help is greatly appreciated. ...

CellNav + Edit feature results in the grid taking over focus from elements located outside of the grid

I am currently dealing with an issue in my application where I am using ui-grid along with cellNav and setting editOnFocus=true for certain columns. The problem arises when the END_CELL_EDIT and CANCEL_CELL_EDIT events in the edit feature always trigger gr ...

Striving to incorporate a Facebook like button onto a Sencha toolbar

The issue I'm facing is that the like button isn't visible on my webpage. Here's a snippet of the code: HTML file : . . . <body> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElem ...

Customizing the CSS for pagination in an Asp GridView displays correctly in the Design View, but does not

Using Bootstrap, I have implemented custom CSS for pagination in a gridview. My master page includes: <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> In the aspx page, my gridview code looks l ...

The function chartobject-1.render() is returning an error message stating: "Unable to locate the specified container within the document. This issue is occurring in the

I've encountered an issue while trying to integrate FusionCharts into my Vue.js project. Every time I attempt to render the charts within my components, I consistently run into this error. Here's a snippet of one of the components: <template&g ...

Is it possible to refresh AdSense banner when the router changes?

Is there a way to reload the AdSense banner ads when the router changes? I've been encountering issues trying to re-add the script and HTML properly. Any guidance on how this should be done would be greatly appreciated... This is just a test for one ...

Guide to displaying API data in HTML format

This university assignment involves working on a homework project where I need to utilize a public API in HTML. So far, I have successfully called the public API to display a list of radio channels in the left menu (without adding any click functionality). ...

Receiving updates on the status of a spawned child process in Node.js

Currently, I'm running the npm install -g create-react-app command from a JavaScript script and I am looking to extract the real-time progress information during the package installation process. Here is an example of what I aim to capture: https://i ...