javascript - How can I highlight a specific div from a hash in the URL? -
when user comes website via www.example.com/#div4, division specified in url highlighted #f37736
(orange) , within 2 seconds transition smoothly #00a087
(the default color).
the div
highlighted class
of "fixed-nav-bar".
what i've tried:
var hash = false; checkhash(); function checkhash(){ if(window.location.hash != hash) { hash = window.location.hash; } t=settimeout("checkhash()",400); };
you hash, target division it's class name. you'll change color of div
orange color, animate default color.
you need include jquery color library animate background-color
though, vanilla jquery cannot animate background-color
. can use jquery ui's highlight effect, thought ui library little heavier in size.
$(document).ready(function () { var hash = window.location.hash; $('.' + hash).css('background-color', '#f37736').animate({ backgroundcolor: '#00a087' }, 2000); });
Comments
Post a Comment