Activate css transition using javascript

I have img that I would like to be able to click and have

.image_click:active {
  -webkit-transition-duration: 500ms;
  -webkit-transform: scale(1.5);
}

stay scalable! I understand that only css cannot do this, as I achieve the transition when I click, but lose it when I release the mouse button. Is Javascript a solution for this? Is there a css psudoclass that can do this that I don't know about?

Here is the best example of what I want to activate

.image_flip { 
  -webkit-animation-name: box_walk; 
  -webkit-animation-duration: 1s; 
  -webkit-animation-iteration-count: 1; 
  -webkit-animation-timing-function: linear; 
} 
@-webkit-keyframes box_walk { 0% {} 100% { -webkit-transform:rotateY(180deg); } }
+3
source share
1 answer

Instead of relying on :activethe stylesheet, create a separate class with transformations.

.image_click_clicked
{
    -webkit-transition-duration: 500ms;
    -webkit-transform: scale(1.5);
}

and then add a js click event handler to your element

<img src="foo.png" class="image_click" 
     onclick="this.className='image_click_clicked';" />

, .

+8

Source: https://habr.com/ru/post/1749257/


All Articles