javascript - Z-index on hover -


for website i'm building have image light-grey h1 under it. when hover on image, text should become black , z-index should change sits above image.

the colour change working, z-index isn't. h1 has position: relative added that's not issue.

$('#photo').mouseover(function() {    $('#title').css.zindex = "100"    $('#title').css("color", "#000000")  });
#photo {    z-index: 0;    position: relative;  }    #photo:hover {    z-index: 4;    position: relative;  }    .titles {    position: relative;  }    #title {    position: relative;  }
<div class="projects">    <h1 class="titles" id="title">title</h1>    <a href="#"><img src="https://graph.facebook.com/10158407872045403/picture?type=large" id="photo"></a>  </div>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

alternatively i've tries using

$('#title').css("z-index", "0") 

what doing wrong here?

$('#title').css.zindex = "100" incorrect, $('#title').css("z-index", "0") said you've tried correct — it's just, used 0 there instead of 100. since both photo , title have z-index: 0 , photo after title, photo wins.

if use $('#title').css("z-index", "100"), works (but keep reading):

$('#photo').mouseover(function() {    $('#title').css("z-index", "100");    $('#title').css("color", "#000000")  });
#photo {    z-index: 0;    position: relative;    top: -4em;  }    #photo:hover {    z-index: 4;    position: relative;  }    .titles {    position: relative;    color: grey;  }    #title {    position: relative;  }
<div class="projects">    <h1 class="titles" id="title">title</h1>    <a href="#"><img src="https://graph.facebook.com/10158407872045403/picture?type=large" id="photo"></a>  </div>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

(i added top: -4em; photo did overlap title.)


having said that, try use css instead. if give class a wrapper around img, , put title after rather before (since you're visually making them overlap anyway), can use either adjacent sibling combinator (+) or general (following) sibling combinator (~) , :hover pseudoclass:

.photo-wrapper:hover ~ h1.titles, h1.titles:hover {   z-index: 100;   color: black; } 

that automatically turns title black , moves z-order if user hovers either photo or title:

#photo {    z-index: 0;    position: relative;  }    #photo:hover {    z-index: 4;    position: relative;  }    .titles {    position: relative;    color: grey;  }    #title {    position: relative;    top: -4em;  }    .photo-wrapper:hover ~ h1.titles, h1.titles:hover {    z-index: 100;    color: black;  }
<div class="projects">    <a href="#" class="photo-wrapper"><img src="https://graph.facebook.com/10158407872045403/picture?type=large" id="photo"></a>    <h1 class="titles" id="title">title</h1>  </div>


having said that, wouldn't directly manipulate style of #title that, i'd use css combined class use on .projects:


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -