目前,我正在尝试hover
为图像贴图实现效果。我在悬停时交换图像,替换图像的地图部分用“悬停”颜色填充。
<map name="Map">
<area id="france" shape="poly" coords="98,133,123,129,151,116,165,129,188,140,181,156,175,167,177,176,181,195,171,203,153,201,145,209,110,196,119,171,110,149,94,141" href="/page/france">
<area id="england" shape="poly" coords="94,119,114,115,139,116,150,100,130,69,117,75,119,89,115,106" href="/page/england">
<area id="wales" shape="poly" coords="118,87,112,107,99,100,109,86" href="/page/wales">
// many more areas //
</map>
jQuery的
$('#england').hover(
function() {
$('img').attr('src', '/lib/img/layout/map-en.gif');
},
function() {
$('img').attr('src', '/lib/img/layout/map.gif');
}
);
它工作得很好。问题是我的图像图中有很多区域。jQuery是否有办法从链接获取href的最后一部分并将其放入动态工作变量中?
逻辑示例:
var identifier = area/href/this
$(identifier).hover(
function() {
$('img').attr('src', '/lib/img/layout/map-'+identifier+'.gif');
},
function() {
$('img').attr('src', '/lib/img/layout/map.gif');
}
);
您可以使用:
$('area').hover(function(){
$('img').attr('src', '/lib/img/layout/map-'+this.href.split('/').pop().slice(0,2) +'.gif');
}, function(){
$('img').attr('src', '/lib/img/layout/map.gif');
});
this.href.split('/').pop().slice(0,2)
接受悬停区域href的最后一个标记的前2个字符。您还可以为您的区域提供更多标准化的标识符(例如“ en”,“ fr”),因此您不必进行此提取。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句