【问题标题】:Change span style when over map area在地图区域上更改跨度样式
【发布时间】:2013-08-21 14:05:37
【问题描述】:

我要做的是在鼠标悬停一个区域时更改跨度的样式(背景颜色)。这可能吗?

好像是这样的(我猜):

span.wind {
    padding: 1px;
    background: red;
    transition: .5s;
    -webkit-transition: .5s
}

area.wind:hover > span.wind {
    background: blue;
    color: #ffffff;
}

完整示例here

【问题讨论】:

    标签: jquery html css imagemap


    【解决方案1】:

    SEE THIS WORKING FIDDLE

    你不能像现在这样用你的 CSS 做你正在尝试的事情,但是你可以在映射区域上放置一个 mouseenter 和 mouseleave 事件,向 span 元素添加和删除一个类,从而非常有效地改变它的样式。这样您就可以在样式表中包含预定义的值,而不是每次都内联添加和删除它们。

    HTML

    <p>Blue <span class="wind_changer">wind</span></p>
    
    <img class="map" width="720" height="305" src="http://www.gloper.org/highplay.pt/images/cultura/logocultura.png" usemap="#usa" />
    
    <map name="usa"><area class="wind" coords="387,9,401,9,414,11,425,17,426,27,418,37,404,42,386,49,353,58,319,66,299,68,273,73,249,76,216,78,183,81,147,84,122,86,103,89,72,92,52,95,24,97,3,97,6,90,57,76,28,84,41,79,73,72,89,72,101,68,108,65,121,62,134,60,150,56,170,51,205,45,224,41,240,36,265,30,280,29,299,23,317,19,342,14,364,11,376,9" shape="poly" title="Blue Wind" /></map>
    

    JS

    $.noConflict();
    jQuery(function() {
        jQuery('.map').maphilight();
        jQuery('.wind').mouseenter(function(){
            jQuery('.wind_changer').addClass('fancy');
        });
    
        jQuery('.wind').mouseleave(function(){
           jQuery('.wind_changer').removeClass('fancy'); 
        });
    });
    

    新的 CSS

    span.wind_changer {
        padding: 1px;
        background: red;
        transition: .5s;
        -webkit-transition: .5s;
     }
    
    .wind_changer.fancy {background:blue;color:#fff;}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-25
      • 2017-04-02
      • 2013-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多