Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade In CSS class

I'm wondering how I can fade in a css class with jquery. The effect I'm looking for is sort of like what you see here: https://squareup.com/

What I've tried so far is this:

$(document).ready(function() {
    $('.mini-nav li').hover(function () {
    $('.hover').fadeIn(slow);
};
});

I thought about the .addClass() method, but I'm not sure where to add it (or if that is the best thing to do).

EDIT: Here is a fiddle of something I've tried: http://jsfiddle.net/J93NR/1/

like image 868
Connor Avatar asked Apr 20 '12 23:04

Connor


2 Answers

you don't need jquery for this, a pure CSS solution is much simpler (fiddle):

<div class="outer"><div class="inner"></div></div>

.outer {
    background: url(...);
}
.inner {
    background: url(...);
    opacity: 1;
    transition: opacity 0.3s;
}
.inner:hover {
    opacity: 0;
}

http://jsfiddle.net/ZAgnY/

like image 171
Lie Ryan Avatar answered Sep 28 '22 07:09

Lie Ryan


<style type="text/css">
#leaf,#leaf:before{background:url(sprite.png)}
#leaf{position:relative}
#leaf:before{content:'\0020';position:absolute;top:0;left:0;display:none}
</style>

<!-- more html -->

<ul id="menu">
  <li id="leaf"><a href="#">Link</a></li>
</ul>

<!-- more html -->

<script type="text/javascript">
$(document).ready(function () {
  $('.min-nav li').hover({
    // Handler in
    function () {
      $("#leaf:before").fadeIn("slow");
    },
    // Handler out
    function () {
      $("#leaf:before").fadeOut("slow");
    }
  });
});
</script>

Of course it would also be possible to achieve this with CSS3 instead of jQuery. Which is exactly what the guys from the website you linked are doing.

like image 34
Fleshgrinder Avatar answered Sep 28 '22 06:09

Fleshgrinder