Last active
January 26, 2017 13:29
-
-
Save fernandosavio/0d4678bf76e273386782e4defe945121 to your computer and use it in GitHub Desktop.
Line highlighting for embedded Gists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery version | |
$(document).on('click', '.js-line-number', function(event){ | |
var elem = $(this).next('.js-file-line'), | |
bg_color = elem.css('backgroundColor'), | |
color_active = 'rgb(248, 238, 199)'; | |
elem.css('backgroundColor', bg_color === color_active ? 'rgba(0, 0, 0, 0)' : color_active); | |
}); | |
var elem = $(document.location.hash).trigger('click'); | |
if (elem.length) { | |
$('html, body').animate({ | |
scrollTop: elem.offset().top | |
}, 800); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Vanilla.js version | |
document.addEventListener('click', function (event) { | |
var elem = event.target, style; | |
if (elem.classList.contains('js-line-number')) { | |
style = elem.nextElementSibling.style; | |
style.backgroundColor = !!style.backgroundColor ? '' : 'rgb(248, 238, 199)'; | |
} | |
}); | |
var elem = document.querySelector(document.location.hash); | |
if (!!elem) { | |
elem.click(); | |
elem.scrollIntoView(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment