如何在图像标记jQuery中显示图像
How to show image in image tag jQuery
我想在每个图像标签后附加一个图像以显示共享按钮。这是小提琴手链接 http://jsfiddle.net/q98up2f3/
$(document).ready(function() {
$("img").each(function() {
if($(this).prop('height')>100 && $(this).prop('width')>100) {
$(this).addClass( "myClass" );
$(this).wrapInner('<img src="https://cdn3.iconfinder.com/data/icons/iconic-1/32/share-128.png" />');
}
});
});
.myclass:hover{
opacity: 0.7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="check">
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
</div>
动态添加类。在检查显示类和注入标签但未反映的元素时
请参阅下面的输出
使用 after() 函数在该特定项目之后插入,请参阅文档
$(document).ready(function() {
$("img").each(function() {
if($(this).prop('height')>100 && $(this).prop('width')>100) {
$(this).addClass( "myClass" );
$(this).after('<img src="https://cdn3.iconfinder.com/data/icons/iconic-1/32/share-128.png" />');
}
$('.myClass').hover(function(){
$(this).next().show();
},function(){
$(this).next().hide();
});
});
});
.myclass:hover{
opacity: 0.7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="check">
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
<img src='http://media-cdn.tripadvisor.com/media/photo-s/05/e4/f7/89/little-venice.jpg'>
</div>
使用以下代码:
$(document).ready(function() {
$("img").each(function() {
if($(this).prop('height')>100 && $(this).prop('width')>100)
{
$(this).addClass( "myClass" );
$('<img src="https://cdn3.iconfinder.com/data/icons/iconic-1/32/share-128.png" />').insertAfter($(this));
}
});
});
http://jsfiddle.net/q98up2f3/1/
相关文章:
- 非常大的图像显示渐进
- CSS Html使图像显示在单选按钮的选项上(单选按钮被CSS隐藏)
- JS照片库.使大图像显示和缩略图可单击
- 多个图像显示带有动态创建的画布的最后一个图像并分配给图像
- 当我在jquery/javascript中单击按钮时加载图像显示
- React图像显示
- 随机图像显示,无重复,使用Javascript
- 将跨度内容(图像url)转换为图像(显示)
- 随机图像显示不止一次
- 节点.js 使用 Multer 上传图像显示未定义
- 范围滑块,用于更改轨道上方对齐圆的直径并使对齐的图像显示在下方
- 使用图像显示和隐藏
- 使用 JavaScript 将文件夹中的图库图像显示到网页中
- 画布到图像显示为无图像(空白)
- 传单不会将本地图像显示为叠加
- 切换此元素时,如何使不同的图像显示,而不是文本
- 在页面加载时将图像显示为弹出窗口
- 如何在模糊浏览器主窗口时将图像显示为叠加层
- iOS在画布上绘制图像显示:无会导致内存泄漏
- JavaScript 图像显示不起作用