简体   繁体   English

我可以使用jquery来操纵CSS以使用base64字符串更改背景图像

[英]Can i use jquery to manipulate css to change background image with base64 string

Here's the problem. 这是问题所在。 i've a base64 image string which is dynamically retrieved from database via ajax. 我有一个base64图像字符串,可以通过ajax从数据库中动态检索该字符串。

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAvsAAAJECAYAAACIHevuAAAgAElEQVR4nO3d

after retrieving the string i want to set it as the background image of a div 检索字符串后,我想将其设置为div的背景图像

<div id="dragBox"></div>

try: 尝试:

$('#dragBox').css('background-image', 'url(' + base64_string + ')');

basically, you just put the base64 inside url() . 基本上,您只是将base64放在url()

more information: "Data URI scheme" Wiki 更多信息: “数据URI方案” Wiki

You can simply place your image data directly into the url parameter of the background property in CSS. 您可以简单地将图像数据直接放入CSS中background属性的url参数中。

#dragBox {
background: url(data:image/png;base64,iv[...]);
}

Here's an example: http://jsfiddle.net/uyrjs/ 这是一个示例: http : //jsfiddle.net/uyrjs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM