Animation after transition on hover?
здарвствуйте, мне нужно что б при наведении кубик плавно появился и когда он появится - анимировался
тоесть animation после transition
<!DOCTYPE html> <html> <head> <style> div { width: 100px; height: 100px; background: red; position: relative; opacity:0; animation-delay: 2s; transition: opacity 2s; } div:hover{ animation: mymove 5s infinite; opacity:1; } @keyframes mymove { from {left: 0px;} to {left: 200px;} } </style> </head> <body> <h1>The animation-delay Property</h1> <p>Start the animation after 2 seconds:</p> <div></div> </body> </html> |
<!DOCTYPE html> <html> <head> <style> div { width: 100px; height: 100px; background: red; position: relative; opacity:0; animation-delay: 2s; transition: opacity 2s; } div:hover{ animation: mymove 5s infinite; opacity:1; } @keyframes mymove { from {left: 0px;} to {left: 200px;} } </style> </head> <body> <h1>The animation-delay Property</h1> <p>Start the animation after 2 seconds:</p> <div></div> </body> </html>
Дополнительно:
Для более продвинутых вещей лучше использовать инструментарий, например GSAP. Конечно средствами CSS и JS это сделать можно, вопрос в том - насколько нужно?
animation объединяет кучу свойств, в том числе и animation-delay
animation сбрасывает animation-delay в значение по-умолчанию — 0.
:root { --transition-duration: 2s; --animation-duration: 5s; } div { width: 100px; height: 100px; background: red; opacity: 0; transition: opacity var(--transition-duration); will-change: transform, opacity; } div:hover { animation: mymove var(--animation-duration) var(--transition-duration) infinite; opacity: 1; } @keyframes mymove { to { transform: translateX(200px); } } |
:root { --transition-duration: 2s; --animation-duration: 5s; } div { width: 100px; height: 100px; background: red; opacity: 0; transition: opacity var(--transition-duration); will-change: transform, opacity; } div:hover { animation: mymove var(--animation-duration) var(--transition-duration) infinite; opacity: 1; } @keyframes mymove { to { transform: translateX(200px); } }
Опишите проблему, и специалист поможет с настройкой, исправлением ошибки или доработкой сайта. Подберём понятный план работ без лишней переписки.
Пока нет других ответов. Будьте первым, кто поможет автору.
Ответить на вопрос
To achieve an animation after a transition on hover, you can use CSS keyframe animations along with the transition property. Here's an example using PHP within the