我有一個互動的世界地圖,您可以將其懸停在不同的大洲上,然後該特定的大陸將產生懸停效果,並將該大陸的名稱放置在該區域上。我用Image映射做了這個,當我在一個區域上空盤旋時,我通過jQuery來更改圖像。像這樣:懸停在區域上時的圖像地圖中的問題
$(document).ready(function() {
$('.map-area').mouseover(function(e) {
var areaId = $(e.target).attr('id');
$('#worldMap').attr('src', 'http://i.imgur.com/' + areaId + '.png');
$('[id^=text_]').removeClass('open');
$('#text_' + areaId).addClass('open');
});
$('.map-area').mouseout(function() {
$('#worldMap').attr('src', 'http://i.imgur.com/5H1hiBU.png');
$('[id^=text_]').removeClass('open');
});
});
.continent-text {
position: absolute;
color: #fff;
text-transform: uppercase;
font-weight: normal;
font-size: 1rem;
}
.continent-text.eu {
display: none;
left: 28%;
top: 35%;
}
.continent-text.eu.open {
display: block;
}
.continent-text.as {
display: none;
left: 40%;
top: 32%;
}
.continent-text.as.open {
display: block;
}
.continent-text.na {
display: none;
left: 8%;
top: 37%;
}
.continent-text.na.open {
display: block;
}
.continent-text.sa {
display: none;
left: 15%;
top: 77%;
}
.continent-text.sa.open {
display: block;
}
.continent-text.af {
display: none;
left: 28%;
top: 60%;
}
.continent-text.af.open {
display: block;
}
.continent-text.oc {
display: none;
left: 46%;
top: 89%;
}
.continent-text.oc.open {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="http://i.imgur.com/5H1hiBU.png" usemap="#image-map" id="worldMap">
<map name="image-map" class="continent-picker">
<area class="map-area" id="OG7CyJf" target="" alt="Europe" title="Europe" href="#" coords="624,190,632,177,615,172,609,162,601,161,608,155,595,142,602,130,597,85,607,78,558,70,508,96,455,212,474,238,501,233,546,222,584,239,588,219" shape="poly">
<area class="map-area" id="epfSt9E" target="" alt="Africa" title="Africa" href="#" coords="593,509,666,473,686,378,664,318,639,321,620,284,608,259,576,241,540,226,471,239,430,339,515,497" shape="poly">
<area class="map-area" id="jx6tE7q" target="" alt="North America" title="North America" href="#" coords="272,347,287,318,310,313,478,104,479,0,1,0,0,159,57,170,97,164,133,236,189,318" shape="poly">
<area class="map-area" id="XFfneee" target="" alt="South America" title="South America" href="#" coords="272,345,286,317,310,314,377,349,411,386,386,466,413,572,268,573,285,436,254,374" shape="poly">
<area class="map-area" id="y4dLClt" target="" alt="Oceania" title="Oceania" href="#" coords="926,393,926,370,970,364,1046,480,1030,557,939,542,898,501,851,501,832,444,891,401" shape="poly">
<area class="map-area" id="ZUqSyEM" target="" alt="Asia" title="Asia" href="#" coords="609,77,633,7,838,8,1074,74,1074,130,954,318,926,370,925,393,888,401,844,416,709,371,664,318,641,321,608,260,588,227,586,222,625,189,631,177,614,171,608,161,601,160,607,155,594,141,601,130,597,84" shape="poly">
</map>
<div class="continent-text eu open" id="text_OG7CyJf">Europe</div>
<div class="continent-text as" id="text_ZUqSyEM">Asia</div>
<div class="continent-text na" id="text_jx6tE7q">North America</div>
<div class="continent-text sa" id="text_XFfneee">South America</div>
<div class="continent-text oc" id="text_y4dLClt">Oceania</div>
<div class="continent-text af" id="text_epfSt9E">Africa</div>
對於文本的更精確的位置,請參閱:https://codepen.io/kerowan/pen/bWEVod
的問題:當你將鼠標懸停在一個區域的文本,該地區開始閃動。我想這是來自jQuery中的mouseover
和mouseout
部分。只要我將鼠標懸停在文本上,jQuery就會將其視爲.map-area
的mouseout
。我不知道如何解決這個問題,向正確的方向推動將是非常感謝!
哇......應該知道......非常感謝! –