You should start using jQuery or some other js lib. This is simpler than js, and you can use it as a shorthand for most js instead of the actually long, elongated js.
Simply put, <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> (or some new goddcd https: // developers. google.com/speed/libraries/devguide#jquery ) in <head> .
Then, inside your event code (much easier if you use jQuery: $.click() for buttons, $.change() for checkboxes, select, radio ...), put the code from your second link, more like
$('#theIDofTheButtonThatTriggersThisAnimation').click(function(){ $('#theIDofTheElementYouWantToSmoothlyScroll').animate({ scrollTop: 0 }, 2000); });
However, if you are trying to make an animation, I recommend that you study some basic css properties, such as position:absolute and position:relative , so as not to go crazy.
I'm still not quite sure what is going on in your code, because it is very non-standard as to how css and jQuery are done now. I would break it into something simple in order to study the general concept.
In your example, you should build your animation example, as I found out: fooobar.com/questions/942423 / ...
I think you are trying to move text up and down based on $.click() . In the violin in my answer, it slides left and right. You can easily reformat up and down using the css top property instead of left .
Once you figure out how to move the entire div up and down, you can make a relative container to hold all the contents of the absolute div and process all the content of the div with a by loop by setting them top s. Here's a quick primer on absolute in relative : http://css-tricks.com/absolute-positioning-inside-relative-positioning/
All my animations have relative and absolute containers. This is how I made a custom gridview plugin that can instantly encrypt the entire database.
In addition, there is no overuse of the div when it comes to animation. Trying to make 1 div make it all a nightmare.
Try to see if it is possible to reformat my violin into a vertical slide. Once you do this, research absolute in relative bit. If you still have any problems, just ask another question.
Change your thinking to these philosophies, and you will begin to fly through this type of coding.