Skip to content

Instantly share code, notes, and snippets.

@axxe16

axxe16/scripts.js

Created Sep 25, 2020
Embed
What would you like to do?
verifica se un elemento fixed su un area #js #fixed #sniff #ishover #jQuery #js #javascript
//restituisce true quando elemento fixed passa sopra ad element
//fixed si passa così $("#rightMenu")
//element si passa sempre così $('#s02')
function isHover(fixed, element) {
var isHover = false;
if ( element.length ) {
var fixed_position = fixed.offset().top;
var fixed_height = fixed.height();
var toCross_position = element.offset().top;
var toCross_height = element.height();
if (fixed_position + fixed_height < toCross_position) {
isHover = false;
} else if (fixed_position > toCross_position + toCross_height) {
isHover = false;
} else {
isHover = true
}
}
return isHover;
}
//sostituisce un immagine con un altra su un immagine target
function replaceImg(target, original, newImg) {
newSrc = target.attr('src').replace(original, newImg);
target.attr('src',newSrc);
}
$(window).scroll(function(){
if(isHover($("#rightMenu"),$('#s02')) || isHover($("#rightMenu"),$('#s04')) || isHover($("#rightMenu"),$('#s06')) || isHover($("#rightMenu"),$('#s08')) || isHover($("#rightMenu"),$('#s02_ep')) || isHover($("#rightMenu"),$('#s03_ep'))) {
$("#rightMenu").addClass('darkMode');
replaceImg($('.navbar-brand > img'), 'logo_creative_hero.png', 'logo_creative_hero_gold.png')
} else {
$("#rightMenu").removeClass('darkMode');
replaceImg($('.navbar-brand > img'), 'logo_creative_hero_gold.png', 'logo_creative_hero.png')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.