[英]How to use image as its own background-image?
如果你想要的是将img标签转换成de 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);
}
要仅模糊图像,请使用以下代码:
.post-cover img {
filter:blur();
}
我不确定你到底在追求什么。 您的演示图像和结果描述似乎不一致。 根据你的描述,我认为你想要这样的东西。
.post-cover { position: relative; height: 400px; width: 300px; } .post-cover #bg { position: absolute; width: 100%; height: 100%; filter: blur(8px); z-index: -1 } .post-cover #orig { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; }
<div class="post-cover"> <img id="bg" src="http://placekitten.com/g/200/300"/> <img id="orig" src="http://placekitten.com/g/200/300"/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.