Stopping a velocity.js animation once it has completed: is it possible?

For the pulsating effect I'm creating using velocity.js as a fallback for IE9, refer to box2 for CSS animation. If the mouse leaves the box before the animation is complete (wait until pulse expands and then move out), the pulsating element remains visible. https://jsfiddle.net/02vu80kc/1/

$(".box").hover(function () {

    $(this).find('.effect-holder').velocity({
        scale: [1.2, 0.9],
        opacity: [1, 0]
    }, {
        easing: 'ease-out',
        duration: 800,
        loop: true
    }, {
        queue: false
    }).velocity("reverse");

}, function () {

    $(this).find('.effect-holder').velocity("stop");

});

How can I stop the animation on mouseout after the effect is complete?

I'd like to avoid using .removeAttr('style') and prefer the animation to finish before stopping it. Any assistance would be appreciated.

If I use this

$(this).find('.effect-holder').velocity('reverse').velocity("stop");

and if you move the mouse quickly, the animation starts again and sometimes pauses in between.

Answer №1

To avoid issues, consider using .velocity("finish") instead of .velocity("stop"), or implementing separate animations for on and off states, both including a call to "stop" (ensuring proper mouse movement capture).

It's important to understand that the {... loop:true ...} configuration results in the initial animation running indefinitely. As a result, invoking "stop" will trigger an immediate reversal unless you use .velocity("stop", true) to prevent this.

edit: A known issue regarding the "finish" bug has been reported - https://github.com/julianshapiro/velocity/issues/495

edit2: Here's a simple example:

$("box").hover(function() {
    // Mouse over
    this.velocity("stop", true).velocity({
        scale: [1.2, 0.9]
    }, {
        duration: 800,
        loop: true
    })
}, function() {
    // Mouse out
    this.velocity("stop", true).velocity({
        scale: 0.9
    }, {
        easing: "ease-out",
        duration: 800
    })
});

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 is the best way to retrieve widget options when inside an event?

Creating a custom jQuery widget: jQuery.widget("ui.test",{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } Initializing the cu ...

Is it possible to iterate over a non-reactive array in a Vue template without having to store it in a data property or computed property?

Presented below is a static array data: const colors = ["Red", "Blue", "Green"]; To display these values in my markup, I can use the following method in React: import React from "react"; // Static array of colors const colors = ["Red", "Blue", "Green"] ...

The MySQL error wreaks havoc on the Node.js server, causing it to

Whenever there is an error or exception coming from MySQL, my nodejs server ends up crashing. This is the code snippet from my backend where I tried using if-else in the query function to handle the response, but it still crashes the server. Even with try ...

Issue with remounting in Nextjs 13

import { useRouter, useSearchParams, usePathname } from 'next/navigation'; export function useQueryParams() { const pathname = usePathname(); const router = useRouter(); const searchParams = useSearchParams()!; const updateQu ...

Is Python a suitable programming language for developing applications on a Raspberry Pi device?

I'm diving into the coding world for the first time and I have a project in mind - controlling my RC car with my smartphone using a Raspberry Pi 3. Research suggests that I should use Node.JS and JavaScript to create the app, but I'm wondering if ...

Creating a Copy to Clipboard feature in React can be achieved by transferring data from an h1 tag to an input field

I'm trying to extract data from an API into an h1 tag in my app. Is there a way for me to easily copy this data and paste it into an input field? Any help would be greatly appreciated. Thanks! ...

Update the text within a list item using jQuery

Looking for help with a simple UL <ul id=ABC> <li>AAABBBCCC</li> <li>BBBBB</li> </ul> I'm seeking a JavaScript function using jQuery. The function should take one argument, so that if "BB" is entered, it will upda ...

The navigation bar appears to have a different width on mobile view specifically on one page

I created a mobile view navigation that appears correctly on two out of three pages. It spans the full 100% width as intended, but on one page it extends beyond that and causes the layout to look distorted due to the larger navigation bar. I'm not sur ...

Preparing JSON data for creating a wind map with Leaflet

I am currently working on converting netCDF data to JSON in order to use it with leaflet-velocity. This tool follows the same format as the output of grib2json used by cambecc in earth. An example of sample JSON data can be found at wind-global.json. By u ...

Setting a specific time for a div element with opacity: A step-by-step guide

Is there a way to adjust the timing for the appearance of the add-to-cart when hovering over the product-list-item? Currently, it appears when I hover over the item and disappears when I move my mouse away. .product-list-item { position: relative; w ...

The height of the iframe with the id 'iframe' is not functioning as expected

I am trying to set the iFrame's height to 80% and have an advertisement take up the remaining 20%. Code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <iframe id="iframe" src="xxxxxx" style="border: ...

Need to return false even though Jquery form check currently returns true

Upon form submission, the following check is executed: if((formData[4].value == 1 || formData[4].value == 2) && !formData[2].value) { alert('Please fill out the key field'); return false; } else { $.ajax({ url: "/aja ...

Using the power of AJAX, fetch JSON data and render it into display tags

JavaScript Query jQuery.noConflict(); jQuery(document).ready(function(){ jQuery("#stallId").change(function(e){ //prevent default action e.preventDefault(); jQuery.ajax({ url: "getProduc ...

The use of Buffer() is no longer recommended due to concerns regarding both security vulnerabilities and

I'm encountering an issue while trying to run a Discord bot. The code I'm using involves Buffer and it keeps generating errors specifically with this code snippet: const app = express(); app.get("/", (req,res) => { if((new Buffer(req.quer ...

Is incorporating RequireJS into an AngularJS project a valuable decision?

Is it true that AngularJS has its own module loading mechanism built-in and using RequireJS is unnecessary or even inefficient? I am working on an Angular project where the index.html file is becoming quite large. Would incorporating RequireJS help reduc ...

Incorporating fresh CSS styles through Selenium

I am attempting to showcase all the prices available on this page using Selenium and Chrome in order to capture a screenshot. By default, only 3 prices are visible. Is there a way to disable the slick-slider so that all 5 prices can be seen? I have tried r ...

Having trouble fetching the value with the designated ID

I'm encountering an issue with retrieving a value using an id. In my code, I have it set up like this: view <input type="text" value="<?php echo $add->class;?>" name="cls_<?php echo $add->id;?>" id="cls_<?php echo $add->id ...

What is the best way to transfer attribute values from multiple elements and paste them each into a separate element?

I have multiple elements with the tag <a class="banner2">. Each of these elements has a different URL for the background image and href value. <a href="#" target="_blank" class="banner2" style="background-image:url('<?php echo get_templat ...

I am experiencing an issue with mydaterangepicker and primeng where it is not displaying properly in the table header. Can anyone assist me with this

I am attempting to integrate mydaterangepicker () with primeng turbotable (since primeng calendar does not meet the requirements), but I am having trouble with its display. Could you please assist me with some CSS code or suggest an alternative solution? ...

Is there a way to position the text to the right and the image to the left?

I have written the following code: <!DOCTYPE html> <html> <head> <title>UMass Boston Computer Science Club About page</title> <link href='https://fonts.googleapis.com/css?family=Chakra Petch' rel='sty ...