Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:02:05+00:00 2026-06-06T09:02:05+00:00

Consider we have a simple cycling Javascript process as: function test() { el=document.getElementById("test"); var

  • 0

Consider we have a simple cycling Javascript process as:

function test() {
    el=document.getElementById("test");
    var opacity = 1;
    var id = setInterval(function() {
    opacity = opacity - 0.1;
    el.style.opacity= opacity;
    \\ if(mouseout) {clearInterval(id);} How to do this?
    if(opacity == 0) {clearInterval(id);}
    }, 500);
}

document.getElementById("test").
addEventListener('mouseover', function(){
  test();
});

Upon moveover event, the process initiates and continues until reaching the if condition. How we can define another if condition to stop the process by another event.

In the current example, how we can stop the process (reducing the opacity) upon mouseout event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:02:09+00:00Added an answer on June 6, 2026 at 9:02 am

    Declare your id variable outside the function. Then you can call clearInterval(id) from your mouseout handler.

    Note that you don’t really need the test() function, you can put its contents directly in your mouseover handler:

    var id,
        el = document.getElementById("test");
    
    el.addEventListener('mouseover', function(){
        var opacity = 1;
        id = setInterval(function() {
           opacity = opacity - 0.1;
           el.style.opacity= opacity;
           if(opacity == 0) {clearInterval(id);}
        }, 500);
    });
    el.addEventListener('mouseout', function() {
       clearInterval(id);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem a very silly question. Consider this: I have a simple Boolean
Consider the following scenario We have a simple database that involves two entities: user
I have a single AMQ queue that receives simple messages with string body. Consider
Consider I have a shared function:- Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As
Consider a very simple model where we have locations and each location can have
I have a simple question. Why is it necessary to consider the terminating null
I have a simple question. Why is it necessary to consider the terminating null
Let's say we have a particularly simple function like import scipy as sp def
I have what I'd consider a relatively simple Highcharts chart that I want to
I have a simple photo taking application that has the following design: [Consider the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.