具体实现:
改变img-box中img的src打的同时能够立刻同步到bgimg,以背景图的形式展现,"background-image":"url($('.img-box img').attr('src').substring(0,20))",这里的url要怎么写
<div class="bgimg">
</div>
<div class="img-box">
<img src="img/2.jpg" alt="">
</div>
$(function(){
let h = document.documentElement.clientHeight;
$(".bgimg").height(h) + "px";
$(".bgimg").css({"background-image":"url($('.img-box img').attr('src').substring(0,20))"});
console.log($('.img-box img').attr('src').substring(0,20));
})
冉冉说
相关分类