Check out the following code snippet:
$('html,body').animate({scrollTop: -20 + $('.clsname').offset().top});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
... (additional script lines)
In addition to that, I need to incorporate this code as well:
var $el = $(".clsname"),
x = 2000,
originalColor = $el.css("background");
$el.css("background", "orange");
setTimeout(function(){
$el.css("background", originalColor);
}, x);
I am trying to achieve both scrolling to an element and setting its background color to orange for a duration of 2 seconds. How can I accomplish this?
Please note: Ideally, I would like the orange color to smoothly fade away after 2 seconds.