After hours of experimenting, I finally achieved a smooth scrolling effect with a bounce at the top and bottom. Now, my challenge lies in creating reusable and clean code for this implementation. Perhaps implementing an algorithm could solve this issue?
The main issue I'm facing is switching between <=
and >=
. While I've cleaned up the code to the best of my abilities, I feel there's room for improvement (please let me know if you spot any).
I'm looking to encapsulate this functionality within a reusable function
, like so:
function reusableFunction() {
...
if (num1 >= num2) // One case I have to compare like this
if (num1 <= num2) // Another case, I have to compare like this
...
}
My progress halted at line #86 in the function bounceBack
. If you have suggestions for creating a smoother scrolling and bouncing effect, please share them below. Note that I prefer not to rely on libraries or frameworks like JQuery.
[Insert your JavaScript code here]
[Insert your CSS code here]
[Insert your HTML code here]