单击以打开图像,然后单击以将其关闭
click to open image and click to close it
我有一个缩略图网格,当单击其中任何一个时,它会放大。
我可以做到这一点:打开一个图像(放大),然后再次单击以将其恢复为正常大小。然后我再次点击,但它没有放大。为什么会发生这种情况,我该如何解决这个问题?
$("#thumbs img").click(function() {
$(this).addClass("enlarge");
$("#thumbs img").click(function() {
$(this).removeClass("enlarge");
});
});
#thumbs {
max-height: 400px;
overflow-y: auto;
cursor: pointer;
width: 300px;
}
#thumbs > img {
cursor: pointer;
float: left;
margin: 1px 1px 1px 1px;
}
.enlarge {
transform:scale(3,3);
transform-origin:0 0;
}
<div id="thumbs">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
<img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60">
</div>
您在点击事件中有点击事件? 考虑使用 toggleClass。
$("#thumbs img").click(function() {
$(this).toggleClass("enlarge");
});
相关文章:
- 单击图像时打开“跨度”标记
- 单击图像后如何创建下拉菜单?[引导/角度]
- 当使用 Javascript 单击图像 A 时,如何将图像 B 的 src 更改为图像 A 的 src
- 单击图像滑块计时器的事件
- 单击图像更改图像并调用函数
- 如何通过单击图像按钮打开图像
- Div在单击图像时未执行slideTogle()
- 单击图像时如何播放音乐
- 尝试单击图像并打开模式ajax
- 画布:单击图像
- 使用javascript和php,在单击图像时将其移动到另一个位置
- 单击图像时播放声音
- 单击图像时不会出现圆圈,但对其他人有效
- 图像可以'单击图像时不会显示
- 单击图像时从数据库加载选项id
- 单击图像,获取坐标并将其保存在数据库JavaScript和Rails中
- 单击图像不执行任何操作
- 单击图像几秒钟后,打开一个链接
- 在 IE7 和 IE8 中单击图像时触发的 window.blur
- 如何在悬停图像时显示某些信息,并在单击图像时显示某些内容