HTML 5 File load image as background-image

无人久伴 提交于 2019-12-04 23:52:06

dronus gave me a great answer to this question by posting this link in the comment section: sveinbjorn.org/dataurls_css

You simple have to do the following to use the image data for a css background image: This will save the src data of your image after you create a new and fill and fill it with data using the FileReader()

var imgFileData = $('#image').attr('src') 

Now you simply have to take this var and set it as the background-image url

$('#yourDiv).css({'background-image':'url(' + imgFileData + ')'});
$('#image').hide(); //optional

Read the link to get a better understanding what is happening here, and thanks again to dronus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!