<bdo id='TZhF1'></bdo><ul id='TZhF1'></ul>

      <legend id='TZhF1'><style id='TZhF1'><dir id='TZhF1'><q id='TZhF1'></q></dir></style></legend>

      1. <tfoot id='TZhF1'></tfoot>
      2. <i id='TZhF1'><tr id='TZhF1'><dt id='TZhF1'><q id='TZhF1'><span id='TZhF1'><b id='TZhF1'><form id='TZhF1'><ins id='TZhF1'></ins><ul id='TZhF1'></ul><sub id='TZhF1'></sub></form><legend id='TZhF1'></legend><bdo id='TZhF1'><pre id='TZhF1'><center id='TZhF1'></center></pre></bdo></b><th id='TZhF1'></th></span></q></dt></tr></i><div id='TZhF1'><tfoot id='TZhF1'></tfoot><dl id='TZhF1'><fieldset id='TZhF1'></fieldset></dl></div>

        <small id='TZhF1'></small><noframes id='TZhF1'>

      3. 有没有办法将背景图像设置为 base64 编码图像?

        Is there a way to set background-image as a base64 encoded image?(有没有办法将背景图像设置为 base64 编码图像?)
      4. <legend id='MekeU'><style id='MekeU'><dir id='MekeU'><q id='MekeU'></q></dir></style></legend>

      5. <i id='MekeU'><tr id='MekeU'><dt id='MekeU'><q id='MekeU'><span id='MekeU'><b id='MekeU'><form id='MekeU'><ins id='MekeU'></ins><ul id='MekeU'></ul><sub id='MekeU'></sub></form><legend id='MekeU'></legend><bdo id='MekeU'><pre id='MekeU'><center id='MekeU'></center></pre></bdo></b><th id='MekeU'></th></span></q></dt></tr></i><div id='MekeU'><tfoot id='MekeU'></tfoot><dl id='MekeU'><fieldset id='MekeU'></fieldset></dl></div>

      6. <small id='MekeU'></small><noframes id='MekeU'>

          <bdo id='MekeU'></bdo><ul id='MekeU'></ul>
              <tfoot id='MekeU'></tfoot>

                  <tbody id='MekeU'></tbody>
                  本文介绍了有没有办法将背景图像设置为 base64 编码图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 JS 中动态更改背景,并且我的图像集采用 base64 编码.我试试:

                  I want to change background dynamically in JS and my set of images is in base64 encoded. I try:

                  document.getElementById("bg_image").style.backgroundImage = 
                     "url('http://amigo.com/300107-2853.jpg')"; 
                  

                  完美的结果,

                  但我没有这样做:

                  document.getElementById("bg_image").style.backgroundImage = 
                     "url('data:image/png;base64,iVBORw0KGgoAAAAAAAAyCAYAAAAUYybjAAAgAElE...')";
                  

                  也没有

                  document.getElementById("bg_image").style.backgroundImage = 
                     "data:image/png;base64,iVBORw0KGgoAAAAAAAAyCAYAAAAUYybjAAAgAElE...";
                  

                  有什么办法吗?

                  推荐答案

                  我尝试和你做同样的事情,但显然 backgroundImage 不适用于编码数据.作为替代方案,我建议使用 CSS 类以及这些类之间的更改.

                  I tried to do the same as you, but apparently the backgroundImage doesn't work with encoded data. As an alternative, I suggest to use CSS classes and the change between those classes.

                  如果您正在动态"生成数据,则您可以动态加载 CSS 文件.

                  If you are generating the data "on the fly" you can load the CSS files dynamically.

                  function change() {
                    if (document.getElementById("test").className == "backgroundA") {
                      document.getElementById("test").className = "backgroundB";
                      document.getElementById("test2").className = "backgroundA";
                    } else {
                      document.getElementById("test").className = "backgroundA";
                      document.getElementById("test2").className = "backgroundB";
                    }
                  }
                  
                  btn.onclick = change;

                  .backgroundA {
                    background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RDUxRjY0ODgyQTkxMTFFMjk0RkU5NjI5MEVDQTI2QzUiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RDUxRjY0ODkyQTkxMTFFMjk0RkU5NjI5MEVDQTI2QzUiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpENTFGNjQ4NjJBOTExMUUyOTRGRTk2MjkwRUNBMjZDNSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpENTFGNjQ4NzJBOTExMUUyOTRGRTk2MjkwRUNBMjZDNSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PuT868wAAABESURBVHja7M4xEQAwDAOxuPw5uwi6ZeigB/CntJ2lkmytznwZFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYW1qsrwABYuwNkimqm3gAAAABJRU5ErkJggg==");
                  }
                  
                  .backgroundB {
                    background-image: url("data:image/gif;base64,R0lGODlhUAAPAKIAAAsLav///88PD9WqsYmApmZmZtZfYmdakyH5BAQUAP8ALAAAAABQAA8AAAPbWLrc/jDKSVe4OOvNu/9gqARDSRBHegyGMahqO4R0bQcjIQ8E4BMCQc930JluyGRmdAAcdiigMLVrApTYWy5FKM1IQe+Mp+L4rphz+qIOBAUYeCY4p2tGrJZeH9y79mZsawFoaIRxF3JyiYxuHiMGb5KTkpFvZj4ZbYeCiXaOiKBwnxh4fnt9e3ktgZyHhrChinONs3cFAShFF2JhvCZlG5uchYNun5eedRxMAF15XEFRXgZWWdciuM8GCmdSQ84lLQfY5R14wDB5Lyon4ubwS7jx9NcV9/j5+g4JADs=");
                  }

                  <div id="test" height="20px" class="backgroundA">
                    div test 1
                  </div>
                  <div id="test2" name="test2" height="20px" class="backgroundB">
                    div test2
                  </div>
                  <input type="button" id="btn" />

                  我在这里摆弄它,按下按钮,它将切换 div 的背景:http://jsfiddle.净/egorbatik/fFQC6/

                  I fiddled it here, press the button and it will switch the divs' backgrounds: http://jsfiddle.net/egorbatik/fFQC6/

                  这篇关于有没有办法将背景图像设置为 base64 编码图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                    <tbody id='TDNc9'></tbody>
                  <legend id='TDNc9'><style id='TDNc9'><dir id='TDNc9'><q id='TDNc9'></q></dir></style></legend>

                      <small id='TDNc9'></small><noframes id='TDNc9'>

                      • <bdo id='TDNc9'></bdo><ul id='TDNc9'></ul>
                        <tfoot id='TDNc9'></tfoot>
                            <i id='TDNc9'><tr id='TDNc9'><dt id='TDNc9'><q id='TDNc9'><span id='TDNc9'><b id='TDNc9'><form id='TDNc9'><ins id='TDNc9'></ins><ul id='TDNc9'></ul><sub id='TDNc9'></sub></form><legend id='TDNc9'></legend><bdo id='TDNc9'><pre id='TDNc9'><center id='TDNc9'></center></pre></bdo></b><th id='TDNc9'></th></span></q></dt></tr></i><div id='TDNc9'><tfoot id='TDNc9'></tfoot><dl id='TDNc9'><fieldset id='TDNc9'></fieldset></dl></div>