kswedberg / jquery-smooth-scroll

Automatically make same-page links scroll smoothly
MIT License
1.97k stars 427 forks source link

Improvement suggestion: allow more control over speed Auto (option) formula #112

Open diegocanal opened 5 years ago

diegocanal commented 5 years ago

Hi Karl,

When having very long pages the (current scroll position - target scroll position) / autoCoefficient formula does not provide us with enough control to get a reasonable balance between anchor links that have their targets very close to them and the ones that have their targets far away from them, i.e., If:

I suggest to create an extra option, apart from autoCoefficient so we'd end up with the formula: (current scroll position - target scroll position + NewOption) / autoCoefficient

I've tried it and it works much better, for example, for autoCoefficient: 9 I have modified the code into:

speed = (delta + 20000) / opts.autoCoefficient;
    }

You can see it in action here: 28 ejemplos de modificación de medidas por un abogado en Madrid. Please, try the anchor links:

  1. Cambios que te afectan a ti o a tu ex (sección 2)
  2. Cambios que afectan a tus hijos (sección 3)
  3. Cambios legales o jurisprudenciales (sección 4)

Thanks!

kswedberg commented 5 years ago

Hi Diego!

This seems fine to me. 2 questions:

  1. any idea on what to name the option?
  2. Does it need to be so precise? For example, maybe it would be nicer for user to enter a value like 20, so the code would read: speed = (delta + (1000 * opts.newOption) / opts.autoCoefficient;

thoughts?

diegocanal commented 5 years ago

Hi Karl!

I appreciate you have taken the suggestion into consideration.

Answering your questions:

  1. Some ideas: maxSpeedLimiter, maxSpeedOffset, maxSpeedBalancer, maxSpeedAdjustment, speedLimiter, speedOffset, speedBalancer, speedAdjustment…or simply maxSpeed.
  2. You are absolutely correct, it doesn't need to be so precise. What you propose is perfect, a 2 digit number to be entered by the user –multiplied by 1000 in the formula– will provide plenty enough room to make the right adjustments.

Thanks!