【发布时间】:2015-01-04 06:04:19
【问题描述】:
我在使用数据 url 设置 div 的背景图像时遇到问题。这是我的代码,它不会抛出错误但也不起作用:
profilePhotoData= shout.get("authorProfPic");
src = 'data:image/png;base64, ' + profilePhotoData.base64
outerDiv.style.backgroundImage="url("+src+")";
【问题讨论】:
-
尝试删除
base64,之后的字符串中的空格 -
不幸的是没有解决它
-
如果您的
div没有内容...因此没有大小...您不会看到它。添加空格或调整width和height将允许您看到背景图像。正如您在下面的评论中提到的,您可能需要缩放图像。通过为background-size选项设置一个值。 Here is a run down
标签: javascript html image background-image