How to stop a function through the console?

Asked

Viewed 452 times

2

I would like to stop a fadein() while running so that the screen looks exactly as it did at the time I stopped.

The ideal would be something generic, that works for fadein, slideup, slideDown, setTimeout etc.

Is it possible to do this using the browser console? How would it be?

NOTE: Just for information, I want to do this so I can get the css of the item at the time of transition, because it is a component and it changes the classes and consequently the css...

1 answer

2

$( "seu-elemento" ).stop();

This method serves to stop animations in general.

.(stop) | jQuery API

Example taken from jQuery:

// Start animation
$( "#go" ).click(function() {
  $( ".block" ).animate({ left: "+=100px" }, 2000 );
});
 
// Stop animation when button is clicked
$( "#stop" ).click(function() {
  $( ".block" ).stop();
});
 
// Start animation in the opposite direction
$( "#back" ).click(function() {
  $( ".block" ).animate({ left: "-=100px" }, 2000 );
});
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>stop demo</title>
  <style>
  div {
    position: absolute;
    background-color: #abc;
    left: 0px;
    top: 30px;
    width: 60px;
    height: 60px;
    margin: 5px;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<button id="go">Go</button>
<button id="stop">STOP!</button>
<button id="back">Back</button>
<div class="block"></div>
 
</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.