javascript - get the background image dimension -
i want make design responsive need background image dimension (width, height) using javascript or jquery. ideas ?
<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>
$(window).on("load", function () { var img = new image(); img.src = $('.slot').css('background-image').replace(/.*\s?url\([\'\"]?/, '').replace(/[\'\"]?\).*/, ''); alert( img.width + ' , ' + img.height); });
here fiddle link: https://jsfiddle.net/beroza/a01y1me4/
Comments
Post a Comment