Lab 6 Reflection
Now the animation would stop but some animations done afterwords would look weird. A way to resolve this was by creating a reset button. Again, I added a button to the HTML, id="reset", and opened up a .click() function for it in jQuery. However, resetting the square would be a bit more complicated than stopping animation. First, I needed to create a global variable, var shapeCopy, and store a .clone() of the shape variable, which itself stores the square. In all, it looked like var shapeCopy = shape.clone();. What .clone() does is create a clone of the selected element in the state it was in when cloned and storing it in a global variable means that the clone can be referenced to in any part of the code via the variable. This comes in handy for the reset's .click() function since now I can store a clone of this variable in a local variable, var replacement = shapeCopy.clone();, and use this line of jQuery to reset the shape, shape.replaceWith(replacement);. This line of code replaces the selected element with the element in parenthesis. The animations fail to work, however, after the replacement so using this line, shape = replacement, I enable animations to work once more. Since shape was replaced with replacement, shape.animate() didn't work since shape no longer existed but now that replacement, what replaced shape, is stored in shape, animations work once more.
These skills are important for a web designer since sometimes the user might not have a nice experience using animations, such as when their Internet has low bandwidth and doesn't allow for it, so they must be given an option to disable it. This means websites you build can cater to all the needs and limitations of your audience, leaving as little left behind in terms of accessibility. Also, knowing how to reset elements of your page after they've been changed makes it convenient for the user to not have to refresh to go back to the original state themselves. Overall, these skills allow you to create a smooth experience for your audience.
Comments
Post a Comment