Experience the smooth transition effects of sliding down the login box when hovering over an image or div

Is there a way to switch the hover js transition effect to a different transition type like fadeIn, fadeOut, or simple transitions?

Check out this link for more details.

Here is an example of the HTML code:

<img id="login-trigger" src="http://www.jointcommission.org/assets/1/6/button-login.jpg" />
<div id="login-box">
    <p>Login now:</p>
    Username : <input />
    <br />
    Password : <input />
</div>

And here is an example of the JavaScript code:

$('#login-trigger, #login-box').on({
    mouseenter: function(e) {
        if (e.target.id == 'login-trigger') $('#login-box').slideDown('slow');
        clearTimeout( $('#login-box').data('timer') );
    },
    mouseleave: function() {
        $('#login-box').data('timer', 
            setTimeout(function() {
                $('#login-box').slideUp('slow')
            }, 300)
        );
    }
});

Any ideas on how to achieve this? Your input would be greatly appreciated. Thank you!

Answer №1

To implement a smooth transition effect, simply replace the .slideDown and .slideUp with their corresponding (and opposite) responses in the code snippet provided below:

http://jsfiddle.net/xjLVE/18/

$('#login-trigger, #login-box').on({mouseenter: function(e) {
    if (e.target.id == 'login-trigger') 
        $('#login-box').fadeIn('slow'); //Changed to fadeIn
        clearTimeout( $('#login-box').data('timer') );
}, mouseleave: function() {
    $('#login-box').data('timer', setTimeout(function() {
            $('#login-box').fadeOut('slow')  //Changed to fadeOut
    }, 300));
    }
});

Answer №2

Consider trying out an alternative jQuery effect such as .fadeOut()

 $('#login-trigger, #login-box').on({
    mouseenter: function(e) {
        if (e.target.id == 'login-trigger') $('#login-box').slideDown('slow');
        clearTimeout( $('#login-box').data('timer') );
    },
    mouseleave: function() {
        $('#login-box').data('timer', 
            setTimeout(function() {
                $('#login-box').fadeOut('slow')
            }, 300)
        );
    }
});

http://jsfiddle.net/H8TaV/

Answer №3

Learn more about jQuery animate here

$('#login-trigger, #login-box').on({
    mouseenter: function(e) {
        if (e.target.id == 'login-trigger') $('#login-box').slideDown('slow');
        clearTimeout( $('#login-box').data('timer') );
    },
    mouseleave: function() {
        $('#login-box').data('timer', 
            setTimeout(function() {
                $( "#login-box" ).animate({
                                        opacity: 0.15,
                                        left: "+=50",
                                        height: "toggle"
                                      }, 5000, function() {
                                        // Animation complete.
                                          $('#login-box').slideUp('slow')
                                      });

            }, 300)
        );
    }
});

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

issue with a non-functional sticky sidebar within a Tailwind post

I am trying to create a layout similar to this website. One of the key features I want to replicate is the sidebar that follows you as you scroll. Here is the code I have, but unfortunately, I can't seem to get it to work: <template> <di ...

Create a new visual masterpiece using Canvas by repurposing an

I am currently working on the following code snippet; export default async function draw(elRef : RefObject<HTMLCanvasElement>, tileData : TileProps) { const canvas = elRef.current!; const ctx = canvas.getContext('2d')!; ctx.clearRect( ...

Triggering a page refresh with Framework7

Currently, I am in the process of developing a compact webapp utilizing the framework7 split-view-panel example. This eases navigation by providing a left-hand navigation bar that, upon clicking, loads a URL in the right-hand panel. However, I have notice ...

What could be causing the pause function for videos to stop working in Chrome?

Recently, I've encountered an issue with the pause() function in Chrome while trying to stop a video playback. Despite using this method successfully in the past with Firefox, it seems to no longer work on Chrome browsers. I've simplified my code ...

What could be causing the issue with the variable appearing as undefined in

My class has a property: public requestLoadPersonal: Personal[] = []; As well as a method: private filterByGender(selectedValue: any): void { console.log(this.requestLoadPersonal); this.requestLoadPersonal = this.requestLoadPersonal.filter( ...

Issue with Animate.css animations not working in my Vue 3 application

My goal is to incorporate some basic HTML animations into my Vue 3 application, however I am encountering issues with the Animate.css examples. More specifically, even after installing the animate css dependency using npm install animate.css --save, the s ...

Changing the z-index using createjs

Is there a way to ensure that the dragged item always stays on top when moved? How can I prevent it from getting dragged underneath another object? Can I specify which "sequenceNumbers" should be moved to the top of the sorting order? //++++++++ ...

Issue with integrating SQL and PHP/HTML using a web form

I've encountered some challenges while attempting to create a social network database, specifically with inserting values into the user_ table. The database setup is in place, but there are no updates happening (no output code when redirecting to PHP ...

What are the steps to ensure that data retrieved from an API is accurately displayed in a table?

My current goal is to collect data from the crypto compare API and display it in a table format. Although I am able to generate the necessary elements and append them to the table body, I am facing an unusual issue. Each time I use a for loop to iterate th ...

Arrange Vuetify elements in a single page stack

How can I stack two UI components on one page using Vuetify? I've attempted to combine elements within a single bracket, but I keep receiving error messages. When I stack components in separate brackets, only the bottom template appears in the fronten ...

Managing the position of the caret within a content-editable div

I need help with editing a contenteditable div in HTML <div contenteditable="true" id="TextOnlyPage"></div> Here is my jQuery code: var rxp = new RegExp("(([0-9]+\.?[0-9]+)|([0-9]+))", "gm"); $('#TextOnlyPage').keyup(function( ...

Updating cannot be done while rendering, within the onError function of the Image

I recently encountered a warning stating that I cannot update during render. The recommendation was to update in ComponentWillMount. However, since I need to change the state after checking if the image is in an Error (not Loaded) state, I must make the ...

What is the best way to extract JSON data from a remote URL?

Having recently started with JavaScript, I am looking to parse JSON from an external URL using pure JavaScript. Currently, I have the following code: var getJSON = function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, tr ...

When working with Node.JS, is it necessary to include 'event' if you include 'net' using the require statement?

As I examine the code, I notice that there is no instance of "require('event')" present. However, there is this piece of code: server.on('error', function (e) { if (e.code == 'EADDRINUSE') { console.log('Address in ...

Steps for transforming a JSON into a Class to generate objects

My JSON data is displayed below: var nodeclienthash={ socket:null, init : function() { // Initializing socket.io this.socket = new io.Socket(this.config.host, {port: this.config.port, rememberTransport: false}); } }; I am currently looking t ...

When comparing strings, if they match, replace them with bold text

Today, I faced a challenging brain teaser that kept me occupied for over an hour. The task at hand is to compare two strings: the text input from the field and data-row-internalnumber. The goal is to determine if they match and then bold only the last let ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Use JavaScript to add a div element to the page ten times every time the button is clicked

Here is the code I have written: $(document).ready(function () { $('<button class="btn more">View More</button>') .appendTo(".listing-item-container") .click(function() { $(this).closest(". ...

Ensuring that $.each properly processes all deferreds in jQuery

I am currently working with the following jQuery code: myFunc: function(cmd, obj){ var idToExtMap = this.map; var requireRes = this.reqInst; var deferreds = []; var ret = true; $.each(idToExtMap[cmd], function( ...

Access nested JSON data through the use of a datatable

I have been attempting to find a solution, but I keep encountering errors. Can someone please assist me? Here is the JSON data: { "siteList": [ { "siteName": "Site1", "deviceList": [ { &quo ...