我有一张图片,我只是试图通过点击图片上的任何位置来将其展开为全屏。所以,我将这幅图像作为DIV的背景。我遇到了javascript问题:特别是针对CSS。请让我知道通过使用jsfiddle。单击按钮时,我怎样才能将DIV拉伸为全屏?
这里是我当前的尝试:http://jsfiddle.net/Muimi/hSzq7/
$(document).ready(function(){
$('.beforeClick').click(function(){
$('.beforeClick').css(div#stretch'width',"33fpx");
$(this).css(div#stretch'width',"100%");
});
});
div#stretch{
height: 334px;
width: 640px;
background-image: url(http://i.investopedia.com/inv/articles/slideshow/6-generic-products/generic-just-as-good.jpg);
}
<body>
<div id="stretch"></div>
</body>
添加到你的答案中,你也可以使用背景-size:cover;通过裁剪图像来删除任何边框请参阅http://jsfiddle.net/hSzq7/22/ –
我喜欢这么多 – Nickool
@David Hewitt在裁剪图像时,我决定不要使用'cover'。只是一个猜测,但我假设OP想要完整的形象 – Turnip