【发布时间】:2014-10-01 09:58:01
【问题描述】:
我正在尝试构建一个图像映射链接,将图像换成另一个图像。这个想法是用户可以单击一个小的定义区域(即“单击此处”),图像将切换到第二个图像。第二张图片会有一个小区域,上面写着“上一个”,因此单击同一区域将使图片恢复到原始区域。
据我所知,到目前为止没有图像更改,但是图像映射似乎正在工作。
谁能弄清楚如何让它正常工作?
html:
<div id="picture_here">
<img src="https://www.google.com.au/images/srpr/logo11w.png" id="picture" usemap="#imageMap"/>
</div>
<map name="imageMap">
<area shape="rect" coords="0,0,100,100" href="JavaScript: test(); void(0);">
</map>
Javascript:
var swapImage = 1;
function test(){
if (swapImage == 1){
swapImage = 2;
$('#picture').attr('src', 'https://s1.yimg.com/rz/d/yahoo_frontpage_en-AU_s_f_p_bestfit_frontpage_2x.png');
}else if (swapImage == 2){
swapImage = 1;
$('#picture').attr('src', 'https://www.google.com.au/images/srpr/logo11w.png');
}
}
【问题讨论】:
标签: javascript jquery html image imagemap