How do I highlight parts of an imagemap on mouseover?

后端 未结 5 1048
旧时难觅i
旧时难觅i 2020-12-13 16:08

I need to display an imagemap with about 70 areas in it. The area of the imagemap the mouse cursor is currently at is supposed to be highlighted in a certain color.

5条回答
  •  长情又很酷
    2020-12-13 16:18

    I tried to use ScottE's solution but unfortunately that meant adding the target image as a body background.

    My solution is very close to his, but uses proper images

    jQuery:

    $(document).ready(function() {
    
        $(".map-areas area").mouseenter(function() {
            var idx = $(".map-areas area").index(this);
            $(".map-hovers img:eq(" + idx + ")").show();
            return false;
        });
        $(".map-hovers img").mouseleave(function() {
            $(".map-hovers img").hide();
            return false;
        });
    
    });
    

    The key concept here is that once you enter the map area, you show the map-hovers image, which then becomes your active layer under the mouse - Simply detecting when you leave that image is what make is smooth.

    HTML: (almost the same, no need for trans image)

    Map / Carte
    Sunset Country North of Superior Algoma's Country Ontario's Wilderness Rainbow Country Ontario's Near North Muskoka
    Sunset Country North of Superior Algoma's Country Ontario's Wilderness Rainbow Country Ontario's Near North Muskoka

提交回复
热议问题