如果你想要的是img标签转换成德div标签brackground,然后
$(".post-cover").each(function(){
var img = $(this).find("img");
$(this).css({
"background-image": "url('"+img.prop("src")+"')",
//Any other CSS background propriety
//If your div don't have a fixed width and height
width: img.width(),
height: img.height()
});
img.remove();
});
对于你的CSS用户模糊效果的下一个样式:
.post-cover{
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
编辑 所以后来同样的JS代码片段,但
<div style="position: relative;">
<div class="blur-content">
</div>
<div class="post-cover">
<img>
</div>
</div>
.post-cover{
position: absolute;
top: 0px;
left: 0px;
}
.blur-content{
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
这种做法几乎是我所需要的。但实际上我需要原始图像在模糊之上,才能获得该效果。 –
看看我编辑的注释 – Makarov
不幸的是,我无法修改我的html结构..所以'blur-content' div无法创建。看起来你的旧JS方法很好,它将图像转换为背景图像属性。难道只是复制'scr ='属性并将其设置为单独的元素(以便能够应用过滤器)?或者在后期div中应用过滤器,并将图像url作为伪元素插入?我不知道什么会适合.. –