CSS lacks hover effects for smooth transitions on mouse over and mouse out

When scrolling down, I've added a transition effect to smoothly change a div element. However, I want to avoid this transition effect when hovering over or moving the mouse out as the div is acting as a button. While I was successful in removing the effect for hover, I couldn't figure out how to address it for mouse out:

Here's the HTML Code:

<div class="navButton"></div>

Corresponding CSS:

.navButton {
    position: absolute;
    top:10px;
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    -ms-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}
.navButton.scroll {
    top:100px;
}
.navButton:hover {
    cursor: pointer;
    -webkit-transition: none;
    -moz-transition: none;
    -o-transition: none;
    -ms-transition: none;
    transition: none;
}

Additionally, jQuery code snippet:

$(function() {
      $(window).scroll(function(event){
        if($(this).scrollTop() > 400){
            $('.navButton').addClass('scroll');
        }; 
      });
});

Answer №1

To achieve this effect, you can use a class toggle on mouseover and mouseout events:

See the Updated Example Here

$('.navButton').on('mouseover mouseout', function () {
    $(this).toggleClass('no-transition');
});
.no-transition {
    -webkit-transition: none;
    -moz-transition: none;
    -o-transition: none;
    -ms-transition: none;
    transition: none;
}

Another approach is to only transition the top property:

Check Out the Updated Example Here

.navButton {
    position: absolute;
    top:10px;
    -webkit-transition: top 0.5s ease-in-out;
    -moz-transition: top 0.5s ease-in-out;
    -o-transition: top 0.5s ease-in-out;
    -ms-transition: top 0.5s ease-in-out;
    transition: top 0.5s ease-in-out;
}

Answer №2

If your aim is to specifically target the transition of the top increase, you can focus on top instead of all:Check out this JS Fiddle example

  -webkit-transition: top 0.5s ease-in-out;
    -moz-transition: top 0.5s ease-in-out;
    -o-transition: top 0.5s ease-in-out;
    -ms-transition: top 0.5s ease-in-out;
    transition: top 0.5s ease-in-out;

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

Tips for adjusting webpage layout automatically based on window dimensions?

As someone who is new to web development, I am in search of a simple solution that allows my developing page to dynamically resize according to the window size without disrupting the layout. Additionally, I am trying to center the page, but experiencing is ...

Converting an array to an HTML form and then executing a submit function

I am feeling a bit overwhelmed because my knowledge of PHP is quite basic, but I am trying to learn as I go. Within a custom Wordpress plugin, there is a PHP function that looks like this: $pool->get_leagues( true ); This function returns an array co ...

jQuery: Gallerific Partially Functioning

Currently, I am attempting to implement the jQuery gallerific plugin on my website located at . The gallery loads correctly, however, both the thumbnail grid and navigation buttons for next/previous images are not functioning as expected. Despite no visi ...

Check if the asp.net textbox meets the criteria of being exactly 19 characters long and is in the correct format using J

I have a web application developed in asp.net, which incorporates both bootstrap and jQuery. I am seeking a way to validate text input based on specific criteria: the text must be exactly 19 characters long and follow this format: - The first three charact ...

The latest update of MS CRM 2013 now includes a version number for WebResources that are of script

I came across an unusual issue in MS CRM 2013 that seems to be intentional, and I need some assistance in finding a workaround for it. The problem is that calling the getScript jQuery method from a WebResource is not possible. In CRM, a version string is ...

Foundation 6: Alignment issues with Top Bar

Exploring Foundation 6 and trying out the sample code. I'm puzzled as to why the "Site Title" is not in alignment with the rest of the top-bar, it seems to be slightly higher up. <div class="top-bar"> <div class="top-bar-title"> ...

Place the video element within the Canvas element

I'm trying to incorporate a video player on Canvas. My video has an alpha channel, and I want to play it over a jpg image. This is the code snippet I've put together: <video id="mainVideo" src="item0.mp4"> </video> <canvas id="m ...

implementing a loading status feature in jQuery toggle

When a user clicks a link on my page, content from another page is loaded using jQuery. While it works fine, I want to enhance it by showing a loading status in case it takes some time to load. I believe that it is better for the user to see that something ...

Tips for programmatically adding/removing rows to a table using ReactJS

I'm currently working on a project where I need to dynamically add and delete rows in a table using ReactJS. However, I've encountered an issue - after adding a few rows, the values in each column become the same even if I change them randomly. ...

Jhipster - Simplifying Session Authentication with the Power of Jquery

I have completed the following tasks. Developed a Jhipster application with Http Session Authentication Configured Cors settings I am experiencing issues authenticating through Jquery ajax. I keep encountering the error message below. { "timestamp" : ...

Parsing JSON data repeatedly using JavaScript within an HTML environment

The following code I found on a popular web development website works perfectly: <!DOCTYPE html> <html> <body> <h1>Customers</h1> <div id="id01"></div> <script> var xmlhttp = new XMLHttpRequest(); var url ...

What is the process for generating a submatch for this specific expression?

Trying to extract account status information using a regular expression in the DOM. Here is the specific string from the page: <h3>Status</h3><p>Completed</p> Current regular expression being used: <h3>Status</h3>[&bs ...

Surprising outcomes encountered while attempting to load a text file into an array with JavaScript

Currently, I am in the process of developing an emulator and seeking to compare opcode logs from another functional emulator. The log containing executed opcodes is prepared for comparison and follows this format: //log.txt (10000 lines long) 0 195 33 195 ...

Explanation of undesired newline behavior

I encountered a cross-browser issue where a line in a narrow column breaks too early even though there is space left for the last word to fit perfectly. Initially, I suspected a problem with my stylesheet, but the same issue persisted in a simple fiddle I ...

Ensure the full-width background includes a top margin to prevent the image's top from being cut off (wp-supersized)

I have implemented wp-supersized to create a full-width background that dynamically resizes. You can find more about it here. Check out what I have done so far at this link. My challenge is with a fixed height header set at 154px. I want the top of the i ...

Creating a sleek and dynamic bootstrap navigation bar with alignment challenges

I am facing an issue with the navigation bar I created using Bootstrap. It is not aligning as I want it to. I aim for it to be in line with the first image in the photo menu, which opens when you click on the camera icon. This alignment is important to me ...

Implementing stop loss with node-binance-api: A step-by-step guide

Currently utilizing node-binance-api for trading purposes. I have initiated an order by executing the following lines of code: let adjustLeverage = await binance.futuresLeverage(coin, 2); let res_2 = await binance.futuresMarketSell(coin, quantity); . Subs ...

Receive the button click event outside of the canvas

Is there a way to have separate click events for the button and the ListItem? My focus is on the button click event only, without triggering the ListItem event. Live DEMO import React from "react"; import ReactDOM from "react-dom"; import ListItem from ...

When I try to refresh the page in Angular 8 by pressing CTRL + R, it automatically directs me back

Every time I refresh the page using CTRL + R or F5, or open a new tab, it always redirects to the homepage in my Angular 8 application. Here is my Routes setup: const routes: Routes = [ { path: 'dashboard', component: OrderComponent, canActiva ...

Oops! An issue has occurred: Unable to locate a differ that supports the object '[object Object]' with the type 'object' within Angular

What am I doing wrong? It's working but I got this error in my console. My Model: export class Form { id: number; formTaxID: number; name: string; formYear: number; sectionID: number; createdAt?: Date; updatedAt?: Date; } My Service: ...