1

I want to end my css transition with jquery or js. I don't mean pause, I want to end them, as if they became 100% done. I have css transitions and not animations.

The properties I am using transition on are top and left, and it is a position absolute element.

1
  • 1
    Share your code, so that we can help you. Commented Sep 16, 2018 at 8:37

3 Answers 3

2

You can simply override the transition-property rule to none.

#el {
  position: relative;
  left: 0;
  top: 25px;
  width: 50px;
  height: 50px;
  transition: all 5s linear;
  background: red;
}
body:hover #el{
  left: calc(100vw - 50px);
}
button:active + #el {
  transition-property: none;
}
:root,body{margin:0}
<button>stop transition</button>
<div id="el"></div>

Now how you trigger this is up to you, it can be using a special class, or any other condition.

Sign up to request clarification or add additional context in comments.

Comments

0

Hello your question is kinda ambiguous.

if you are using transition instead of animation you can control the flow of it in the same css example :

   transition: background-color .2s linear 0s; /*Standard*/

If you want to interrupt the transition with JS you can assign other Css valor to an different class name or property when some action you want is triggered.

       .normal{
        transition: background-color .2s linear 0s; /*Standard*/ 
        }  

         [stop = yes] {
          background: black; 
          } 

        document.body.addEventListener('mouseover', function(e){
        e.stopPropagation();
        if(someting you want){
          document.queryselector(".normal").setAttribute("stop","yes");
         }
     else{
       document.queryselector(".normal").setAttribute("stop","no");
      }
     },false);

if something you want were triggered then the atribute will be set to the no transition and this also cut off the running one.

Comments

-1

$('.toggle-animation').click(function(){
  $('.element').stop(true).toggleClass('animating');
});
.element{
    top: 0px;
    left: 0px;
    width: 100px;
    height: 100px;
    position:relative;
    background: red
}
.animating{
    top: 100px;
    left: 100px;;
    transition: all 5s linear 0s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="element"></div>
<button type="button" class="toggle-animation">Click me</button>

1 Comment

uh im pretty sure u posted the exact same code twice on accident

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.