-1

I want to start a transition when I click on a div. Currently my transition happens only when using with css active. I want this transition to happen when I click on this div. How can i do that? I'm using reactjs and i think it should be done using states. But I cannot figure out how to do this.

I have done something like this but it is not working

<div className='vote_card_hover' style={{transform:this.state.toggle? 'translate(-50%, -50%) scale(1)':''}}>

I have switched style using states. when toggle state becomes true i'm doing the transformation. But it is not working

.vote_card_hover {
  position: absolute;
  width: 100px;
  height:100px;
  transition: .3s ease;
  background-color: 'red'
}

.vote_card_hover:before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 110%;
  height: 110%;
  background: rgba(57, 161, 255, 0.5);
  transition: transform 0.5s ease;
  border-radius: 50%;
}

.vote_card_hover:active:before {
  transform: translate(-50%, -50%) scale(1);
}
<div class='vote_card_hover'>
  <a>test</a>
</div>

2

1 Answer 1

0

In this example, I made it like, the animation will keep working from the moment you click on test. So if you want to stop it after the first time. You can change the css property like animation: mymove 1s 1;.

Let me know if it wasn't your requirement.

$('a').on('click', function(){
  $('.vote_card_hover').addClass('active');
})
.vote_card_hover {

    position: absolute;
    width: 100px;
    height:100px;
    transition: .3s ease;
    background-color: 'red'

}

.vote_card_hover:before{

    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 110%;
    height: 110%;
    background: rgba(57, 161, 255, 0.5);
    transition: transform 0.5s ease;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
}

.vote_card_hover.active:before{
    animation: mymove 1s infinite;
}
@keyframes mymove {
    0%   {transform: translate(-50%, -50%) scale(0);}
    50%  {transform: translate(-50%, -50%) scale(1)}
    100% {transform: translate(-50%, -50%) scale(0);}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='vote_card_hover'>
  <a>test</a>
 </div>

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

1 Comment

You can toggle the state onClick of the test and apply the same class using the help of that state.

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.