【发布时间】:2014-07-12 16:53:15
【问题描述】:
我想通过 jQuery 获取这个 HTML 元素的背景图像的像素高度,如何?
<section class="profile-banner" style="background: url(http://www.mydomain.com/images/myimage.png) 50% 50% no-repeat;"></section>
更新
我现在有了这个,但我从来没有看到高度警报框alert('height:' + height);。
为什么?
var url = $('.profile-banner').css('background-image').replace('url(', '').replace(')', '').replace("'", '').replace('"', '');
alert(url);
var bgImg = $('<img />');
bgImg.hide();
bgImg.bind('load', function()
{
var height = $(this).height();
alert('height:' + height);
});
【问题讨论】:
标签: jquery css height inline pixels