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

Implement horizontal scrolling feature to code container

One cool feature on my blog is the codebox where I can insert snippets of HTML, CSS, and Javascript codes. Here's an example of how my CSS code looks: .post blockquote { background-image: url("https://dl.dropbox.com/u/76401970/All%20Blogger%20Tr ...

Utilizing the map() function to iterate through a list of outcomes and assigning the resulting array as the state of a component in ReactJS

Currently, I am facing an issue with assigning an array value to the state in my react project. In order to do this, I have initialized my state as follows: constructor(props) { super(props); this.state = { category: [] } } My objec ...

What is the method to retrieve the class name of an element when the div is created as '<div id 'one' class="element one"></div>'?

I have three elements named one, two, and three, declared as seen below: <div id =container> <div id 'one' class="element one"></div> <div id 'two' class="element two"></div> < ...

Develop a form containing a date input in a special character-free format, along with a validation feature

I am looking to design a form that necessitates users to input a date in the following format: "ddmmyyyy". No slashes, dots, or any other special characters should be included. Only entries matching this specific format will be accepted as valid, any other ...

Run a series of functions with arguments to be executed sequentially upon the successful completion of an ajax request

I am currently working on implementing a couple of jQuery functions to assist me in testing some api endpoints that I am developing in php. While I have limited experience with Javascript and jQuery, I am struggling to figure out what additional knowledge ...

Tips for including parameters in an array of values when using getStaticPaths

I'm trying to retrieve the slug value that corresponds with each number in the getStaticPaths for my page structure: /read/[slug]/[number]. The code I have is as follows: export async function getStaticPaths() { const slugs = await client.fetch( ...

Verify that all elements sharing a common class are concealed

I'm facing a simple issue where I have a list with identical class names. When one of them is clicked, it animates out of the container and then redirects you. The list also includes a hide button. My goal is to receive a browser alert when all items ...

Unable to pass data using $.post() method

I am trying to send some data as a variable using jQuery's $.post() method to a PHP file and then display the result in a div after clicking a button. Unfortunately, I'm facing an issue where the data isn't being retrieved in the PHP file. ...

Prevent users from deleting options in Autocomplete by disabling the backspace key

I am currently working on implementing the Autocomplete component from Material-Ui library to allow users to select multiple options, but I want to restrict them from directly removing any of those options. One issue I've encountered is that users ca ...

The functionality of window.location.href seems to be malfunctioning on mobile devices within an ionic application

Attempting to open a view with a function call from the UI side <ion-option-button class="button-light icon ion-chatbubble" ng-click="openView('username')"></ion-option-button> The controller code for this action is as follows: $sc ...

Utilize Bootstrap4 to position content above the navigation icon

I need assistance to modify my code so that it will have the following appearance: I successfully created a navigation bar icon and inserted the logo, but I am struggling to position the data above the navigation icon: My current code: <nav class="n ...

If the <option> "anyTableName" </option> is chosen, then display the column names of the selected table (PHP, MySQL)

Hey there, I'm a newbie on stackoverflow so feel free to correct me if I'm off base ;) Here's my current dilemma: I have a text.php file that contains 2 <select> elements. The first one allows me to choose a table (like "accounts", "c ...

What is the best way to convert my Chatbot component into a <script> tag for seamless integration into any website using React.js?

I have successfully integrated a Chatbot component into my Next.js application. https://i.stack.imgur.com/BxgWV.png Now, I want to make this component available for anyone to use on their own website by simply adding a tag. My initial approach was to cre ...

Create a list of items with checkboxes next to each that can be repeated using PdfMake

Incorporating pdfMake into my project, I am trying to display text next to an image and replicate this section in my docDefinition. The issue arises when I attempt to repeat this part using the following code snippet: { columns: [ { ...

When I remove a user as admin, I am unable to retrieve all users to update the data table

I am currently working on an Admin Dashboard that includes a section for users. This section features a simple table displaying all the users in the MongoDB database along with some information. Additionally, there are functionalities to add a new user and ...

Smooth transitions between points in animations using the D3 easing function

I'm working on an animated line chart that displays data related to play activities. I've been experimenting with changing the animation style between data points on the chart using d3.ease Currently, my code looks like this: path .attr("stro ...

sending a selection of JSON string values to a jQuery function

I have a JSON string that contains different items, but I am only interested in the 'locked' array and would like to pass it to a jQuery function. The JSON string was generated using json_encode from PHP. {"ignored":[],"status":{"message":"succe ...

Jquery Mobile Photoswipe struggles to manage external pages

I've encountered an issue with Photoswipe and I could really use some assistance. I have a mobile application that utilizes Photoswipe, and everything works fine when both pages are on a single HTML file. However, when I try to load images using param ...

Choose a minimum of one validation for the list item

When I have a form in JSP that includes a drop-down view with multiple options, I want to ensure that at least one option is selected before the form can be submitted. If no options are selected, the form should not be able to submit. Thank you in advance ...

Different width, same height - images arranged side by side in a responsive layout

The problem lies in the images: Here is an example of desktop resolution: I need to use default size pictures (800x450px) on the server. This means I have to resize and crop them with CSS to fit the container div's width while keeping the height con ...