I had this grand idea for the Dinfosec website to have the first thing the user sees is a blury photo and an open lock that when the click on would animate and draw a closed lock then fade away to display the rest of the website. When I thought of this idea originally I was thinking that the users would have a sense of security (pun intended) and reinforce the idea that there information will be safe with this company.
To start of I started researching animation in web development and found a really cool API called Canvas. It was similar to Javascript in its syntax but it was solely designed for pixel manipulation and works with x and y coordinates. After spending about 6 hours trying to understand how the whole thing worked It was suggested that I look into using SVG animations instead as it was more suited to what I was trying to do.
For this I started looking at different libraries with similar SVG animations to the one I wanted for the logo animation. I found 2 potential libraries. The first was Vivus.js, this library worked by first triggering an animation of strokes and then filling it. It also gave a number of different SVG animations that all drew the object onto the screen but in different ways. It seemed easy to implement as well however when I downloaded the files and tested it on my logo the only thing that drew itself was the lock and it didn’t draw it the way I wanted it to. I found out that the other parts wouldn’t work because this library only worked with strokes which was not exactly I was looking for so I decided to keep looking and Vivus.js would be a back up if I couldn’t find any others.
The second SVG library I found was called Draw Fill SVG by a blogger called ‘call me nick’. his animation was designed to draw the stroke and then fade in the fill. This is exactly what I wanted so I happily downloaded the source and followed the instructions to set the animation up and then pasted in my SVG. Unsurprisingly it did absolutely nothing. So fiddled around with it for a while, re-read the instructions and found that I hadn’t added a particular Modernizr.js file so just incase I put every file in the documentation into the file to make sure I didn’t miss anything and the animation still wouldn’t work because it still didn’t pick up that Modernizr was a function. After I copy and pasted the original animation word for word and inserted my SVG the Modernizr problem went away but another JSON problem appeared. The original file had the same problem and it still worked so I didn’t understand why mine wouldn’t.
Fae found another SVG animation method using CSS that I could use to do exactly what Draw Fill SVG was doing using the CSS properties of stroke-dashoffset and stroke-dasharray. The stroke-dashoffset specifies the length between dashes in a stroke pattern. stroke-dasharray controls the pattern of dashes and gaps used to stroke paths. which ultimately creates an animation that looks like the strokes are moving. Yay half way there! next I had to make the fill appear after the animation had finished drawing the logo.
In order for the lock to be a different colour to the rest of the logo I had to create another class that designated the specific colour to that specific area. This the grant scheme of things was easy to do. In order to make the fill come into play I fiddled with the fill property and made it fill out with opacity and transitions to ease in. Of course since everything else was now working the transitions didn’t work. It was only after I put it on the main animation controller class that it faded nicely instead of just appearing after the the animation was finished. In order for the fill to ease in after the animation I had to use a function called setTimeout (function() {…. }time in milliseconds); which tells the computer that after a certain amount of time the do something in this case fill out the logo.
After that the lock was simple I just copied and pasted the code from the logo SVG and changed the paths around so that they would draw the way I wanted them to and wala done!
I’m very happy with end results for both the logo animation and the lock I’m not sure that once they are beside each other that the whole thing may look to much but fingers crossed it’s not.