0

Firstly, What I'm trying to accomplish is when you hover over a thumbnail on the lower left, the other thumbnails will become black. However, what I have now seems wierd as the other images flashes back too quick and has no transition.
Secondly, when you transition between thumbnails, I would like when you hover over a "blackened" image, the image will return with a transition, just like what I have at the bottom of my fiddle example.

I'm sorry for the slight confusion since it's two things combined, but I hope I explained it right.

$('.thumb-box').click(function() {

    var theSRC = $(this).find('img').attr('src');

    $(this).parents('.image-wrapper').find('.main-image').attr('src', theSRC).fadeIn();

});

//Resize image
$('.thumb-box').hover(function(){
        $(this).siblings().find('.child-img').addClass('add-active');
    }, function(){
        $(this).siblings().find('.child-img').removeClass('add-active');
});

$('.main-image').each(function() {
    if ($(this).height() > 550) { 
        $(this).addClass('higher-than-max');
    } else if ($(this).height() <= 550) {
       $(this).addClass('not-higher-than-max');
    }
});
.parent{
    border:1px solid purple;
    height:100%;
    width:80%;
    float:Right;
}
.child{
    border:1px solid red;
    height:100%;
    background:gray;
    text-align:center;
}
.child-img{
    display:inline-block;
    max-width:100%;
    margin:0 auto;
}
.image-wrapper{
    width:100%;
    background:orange;
}
.thumbnails img{
    width:auto;
    height:100%;
    width:100%;
}
.thumbnails{
    width:100px;
    height:100px;
  
}
.thumb-box{
    height:40%;
    width:40%;
    display:inline-block;
    background:black;
}
.higher-than-max{
    max-height:500px;
    width:auto;
}
.not-higher-than-max{
    max-height:100%;
    width:auto;
}
.add-active{
    transition:2s;
    display:none;
}
.boxes{
    height:100px;
    width:100px;
    background:black;
    transition:.5s;
}
.boxes:hover{
    background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
    <div class="child">
        <div class="image-wrapper">
            <img src="http://vignette2.wikia.nocookie.net/pokemon/images/b/b1/025Pikachu_XY_anime_3.png/revision/latest?cb=20140902050035" alt="374x333" class="main-image">
            <div class="thumbnails">
                <div class="thumb-box"> 
                    <img src="http://vignette2.wikia.nocookie.net/pokemon/images/b/b1/025Pikachu_XY_anime_3.png/revision/latest?cb=20140902050035" alt="374x333" class="child-img">
                </div>
                <div class="thumb-box"> 
                    <img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg" alt="800x450" class="child-img">
                </div>
                <div class="thumb-box">  
                    <img src="http://vignette3.wikia.nocookie.net/scratchpad/images/0/02/Pikachu.gif/revision/latest?cb=20150217015901" alt="" class="child-img">
                </div>
                <div class="thumb-box">
                    <img src="http://cdn.bulbagarden.net/upload/thumb/0/0d/025Pikachu.png/250px-025Pikachu.png" alt="" class="child-img">
                </div>
            </div>
        </div>
    </div>

    <div class="accomplish">
        Image Hover Transition:
        <div class="boxes"></div>
    </div>
</div>
Code 3
  • 74
  • 6
Snorlax
  • 4,425
  • 8
  • 37
  • 68

3 Answers3

0

Personally, I would do this with pure CSS using pseudo elements to create the black overlays.

.thumb-box {
  height: 100px;
  position: relative;
  width: 100px;

  // Black overlay
  &:after {
    background-color: #000;
    content: '';
    height: 100%;
    left: 0;
    opacity: 0;// hide overlay to start
    position: absolute;
    top: 0;
    transition: all 250ms ease-in-out;
    width: 100%;
  }
}

// Show all black overlays on hover
.thumbs {
  &:hover {
    .thumb-box:after {
      opacity: 1;
    }
  }
}

// Hide black overlay on individual hovered item
.thumb-box {
  &:hover {
    &:after {
      opacity: 0 !important;
    }
  }
}

Demo: http://jsbin.com/lanuni/edit?html,css,output

Note: I had to add an additional wrapper around each image since you can’t create pseudo elements on <img> tags (see CSS :after not adding content to certain elements).

Community
  • 1
  • 1
Ted Whitehead
  • 1,731
  • 10
  • 18
0

I think the issue is your are trying to transition between display: inline-block and display: none

You can't transition display. See this question: Transitions on the display: property

Community
  • 1
  • 1
zero298
  • 25,467
  • 10
  • 75
  • 100
0

First: it flashes b/c the gap between your thumbnail will force your mouse to hover out, thus create the flickering effect.
to solve this you can use setTimeOut() to delay between hovers.

Second: transition between display:block to display:none don't work well, use opacity instead, and put a black background between your thumbnail

aahhaa
  • 2,240
  • 3
  • 19
  • 30