简体   繁体   中英

Changing image when div is hovered

I'm looking all day for solution. I try to make something like these:

sigma-topline2012.com/en-us/topline-2012/bc-5-12/overview.html#highlight

As you can see, when we move the mouse on description on right, then image is changing. Could anybody can help me with these? Thanks!

Use jQuery hover

http://jsfiddle.net/eah9bgkm/

<img id="image" src="http://placekitten.com/g/130/130" />

<ul>
    <li data-link="http://placekitten.com/g/150/150">Cat 1</li>
    <li data-link="http://placekitten.com/g/151/151">Cat 2</li>
    <li data-link="http://placekitten.com/g/152/152">Cat 3</li>
</ul>

$(document).ready(function(){
    var img = $('#image');
    $('li').hover(function(){
        img.attr('src', $(this).data('link'));
    });    
});

Just add a css class to fadein/out

Try this:

<div id="definition1">Definition 1</div>
<div id="definition2">Definition 2</div>
<img id="imageWrapper" src="image1.png" />

Javacript:

$("#definition1").hover(function(){
    $('#imageWrapper').attr("src", function(index, attr){
        return attr.replace("image1.png", "image2.png");
    });
}, function(){
    $('#imageWrapper').attr("src", function(index, attr){
        return attr.replace("image2.png", "image1.png");
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM