Home › Forums › Support › Start animation when div comes in viewport This topic has 9 replies, 2 voices, and was last updated 7 years ago by Tom. Viewing 10 posts - 1 through 10 (of 10 total) Author Posts November 16, 2017 at 2:23 am #425730 Manuel hi all, it’s not a specific GP question. i’m looking for a code snippet to start an animation when the div comes in viewport. This is what i have: @keyframes fadeIn{ 0% { opacity:0; } 100% { opacity:1; } } .test-animation { animation: fadeIn 2s } Anoyone can help? Best regards an thanks to Tom and the crew for a very nice Theme ๐ November 16, 2017 at 9:49 pm #426445 TomLead Developer Lead Developer I assume that CSS isn’t working? Without javascript, using keyframes is probably the way to go. November 16, 2017 at 10:02 pm #426452 Manuel Thanks for the fast reply! All the JavaScript I’ve found didn’t seem to work. So, if someone have a working code to show animation when it comes in viewport please let me know. Thanks a lot and best regards. November 16, 2017 at 10:08 pm #426458 TomLead Developer Lead Developer You could give the div a class: hidden-on-load Then add some CSS: .hidden-on-load { opacity: 0; transition: opacity 300ms ease-in-out; } Then some javascript in the wp_footer hook: <script> jQuery( document ).ready( function($) { $( '.hidden-on-load' ).removeClass( 'hidden-on-load' ); } ); </script> Not tested, but may do the trick. November 17, 2017 at 2:14 am #426572 Manuel Thanks a lot for your code but it also didn’t seem to work. No problem cause it is nothing GP specific. Thanks again for the great support. November 17, 2017 at 9:17 am #426912 TomLead Developer Lead Developer Did it do anything at all? November 17, 2017 at 9:38 am #426946 Manuel Not really. here’s a link to my site. it’s just a testside. the div with the class “hidden-on-load” is at the bottom of the content div. My Testsite Thanks November 17, 2017 at 3:06 pm #427124 TomLead Developer Lead Developer Ahh when it comes into viewport – that’s much more difficult. Perhaps this topic will help: https://stackoverflow.com/questions/23180375/fade-in-div-when-its-scrolled-into-viewport November 17, 2017 at 3:10 pm #427127 Manuel I’ll give it a try. Thanks again. November 17, 2017 at 3:24 pm #427143 TomLead Developer Lead Developer No problem ๐ Author Posts Viewing 10 posts - 1 through 10 (of 10 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In