2011-08-07 63 views
4

我在我的网页和iPad应用程序上使用图像地图。图像映射中的每个区域都是一个可点击的元素,用于制作声音,这可以通过jQuery轻松完成。但是我无法改变样式,比如显示边框,或者改变填充颜色来指示区域被点击。如果有人这样做,请让我知道;这似乎很简单,但我真的很难过。如何更改图像地图区域元素样式

+0

你能告诉我们一些代码吗? –

+1

这里是我的代码: <地图名称= 'facepagemap'> <区域ID = “1” 形状= 'RECT' COORDS = '441451506500'/> <区域ID = “2” 形状= '矩形' COORDS ='511,439,583,512'/> –

+0

$('area')。click(function(e){\t //更改区域样式}; –

回答

6

我得到它的工作感谢James Treworgy's awesome ImageMaster Jquery plugin

$('area').mousedown(function(e) { 
    $(this).mapster('set',true); 
}); 

$('area').mouseup(function(e) { 
    $(this).mapster('set',false); 
}); 

$('area').bind("touchstart", function(e){ 
    $(this).mapster('set',true); 
}); 

$('area').bind("touchend", function(e){ 
    $(this).mapster('set',false); 
}); 
+0

我试图使用您的代码,但它给了我一些错误..我也使用了插件。但仍然无法正常工作..控制台显示此错误TypeError:$ .mapster_when是未定义的延迟:$ .mapster_when.defer, – Amit

+0

@Amit是否解决了TypeError:$ .mapster_when问题。我也面临同样的问题。你能帮我回顾一下这个错误吗? – DRAJI

-1

很难说没有看到代码,但是你引用地图部分的方式与应用样式的方式是一样的。

如果你有section1 ID,那么你的CSS可能是

#section1{ 
    border://something 
    background-color://something else 
} 

或者,在你的脚本,当你引用一下,你还可以添加一些风格,例如,

$('#section1').click(function(){ 
    //whatever 
    $(this).css({'background-color' : 'red', 'border' : '1px solid black'}); 
}); 
+0

感谢您的快速回复,我的代码在评论中。$(this).css('...')不起作用。 –