我想让这个设计的反应,我将需要的背景图像尺寸(宽度,高度)使用javascript或JQuery。有什么想法吗?
<div class="container">
<div id="result" class="result"> </div>
<div class="slot-container">
<div id="slot1" class="slot"></div>
<div id="slot2" class="slot"></div>
<div id="slot3" class="slot"></div>
<div><button id="control" class="btn">START</button></div>
<div id="try" class="result try">TRY 0</div>
</div>
</div>
发布于 2015-09-30 09:05:08
$(window).on("load", function () {
var img = new Image();
img.src = $('.slot').css('background-image').replace(/.*\s?url\([\'\"]?/, '').replace(/[\'\"]?\).*/, '');
alert( img.width + ' and ' + img.height);
});
发布于 2015-09-30 08:04:33
您可以使用以下命令:
var img = new Image;
img.src = $('body').css('background-image').replace(/url\(|\)$/ig, "");
var bgImgWidth = img.width;
var bgImgHeight = img.height;
https://stackoverflow.com/questions/32855583
复制相似问题