PhoneGap SVG 作为 iOS 上的 data-uri

Posted

技术标签:

【中文标题】PhoneGap SVG 作为 iOS 上的 data-uri【英文标题】:PhoneGap SVG's as data-uri's on iOS 【发布时间】:2014-01-15 13:32:17 【问题描述】:

似乎是一个奇怪的问题,我可以在桌面上的 Chrome 上看到我的 SVG,但当我将它编译到手机时却不行。

如果我使用 Safari 检查元素,然后选择 iPhone 模拟器,我可以看到 Data-URI,然后当我在计算机上单击它时,我可以看到图像。

我绝对可以看到具有正确高度和宽度的 div,但我看不到 SVG 背景图像。

据我所知,这完全支持 ios 3.2 及更高版本 - http://caniuse.com/svg 和 http://caniuse.com/datauri

代码是:

span 
        background:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjcxIiBoZWlnaHQ9IjQ4IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj4KIDwhLS0gQ3JlYXRlZCB3aXRoIE1ldGhvZCBEcmF3IC0gaHR0cDovL2dpdGh1Yi5jb20vZHVvcGl4ZWwvTWV0aG9kLURyYXcvIC0tPgogPGc+CiAgPHRpdGxlPmJhY2tncm91bmQ8L3RpdGxlPgogIDxyZWN0IGZpbGw9Im5vbmUiIGlkPSJjYW52YXNfYmFja2dyb3VuZCIgaGVpZ2h0PSI1MCIgd2lkdGg9IjczIiB5PSItMSIgeD0iLTEiLz4KICA8ZyBkaXNwbGF5PSJub25lIiBvdmVyZmxvdz0idmlzaWJsZSIgeT0iMCIgeD0iMCIgaGVpZ2h0PSIxMDAlIiB3aWR0aD0iMTAwJSIgaWQ9ImNhbnZhc0dyaWQiPgogICA8cmVjdCBmaWxsPSJ1cmwoI2dyaWRwYXR0ZXJuKSIgc3Ryb2tlLXdpZHRoPSIwIiB5PSIwIiB4PSIwIiBoZWlnaHQ9IjEwMCUiIHdpZHRoPSIxMDAlIi8+C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dkNy8zN3AzcmVaNXpkSHlhY2h4bkMxbEY1aEhQSkNxNEprL0lKWEsydjdmZGQwdmx5aXdhVldUWkVTT3VrR0lDaHcySkNVRWY5ekVjY25KaEpVYzVhWG13a3FhY29UeFlHVkpPUng2c2RDaW5KZzlXYXBUVFJrN2t3Z2Q5dEYxVEJDYlJXRUlXSndibzl3akppSmx6RDdsRmJsQUVEajdsakRDU2txWVp0UXFaRENobC9PV2tIR0h2VGtKeUpFZHlKRWR5L2k2SnlRYnFuQ21jNW95MHFOVTVMSHFmVWVlOCt1b2NTSm5CNXlLeWdLVE1qNk1taC8rM2o5d2hWVWg2R1MyVFZwRDFZRStLS0cvSUJiSkRHV3ZJcHB6NGhocjZlT0RZa3BjUEszbkt5Y2lEbFl4dTViL1VPVjFwc05LbG5JWThXR2xRVGdzNU43Y3c4ZVdCUGxvcUFuOHFBZ1BMcEpvK0JLY1BRck55eVpFY3laRWN5Zm12QkpkSjlUZzQrRGhZR3dtKzJVaFFLbGVtMFRoRWRuVWhqZUVXbEFOZVZpc1NFNEkrSHRtZENuSmhwVUE1V1htd2txV2N1RHhZaWNmTUNDM0M5Q2luS1E5V21wUlRSNjdsd2dkOTFGMjlValN1a0VPdkZIMElNQUNpWFpXT2g4VGJiQUFBQUFCSlJVNUVya0pnZ2c9PSIgaWQ9InN2Z18xIiBoZWlnaHQ9IjQ4IiB3aWR0aD0iNzEiIHk9IjAiIHg9IjAiLz4KIDwvZz4KPC9zdmc+');
        background-size:100%;
        display:block;
        width:31px;
        height:20px;
    

【问题讨论】:

【参考方案1】:

我在简短搜索中看到的唯一示例(here 和 here)不使用 base64 编码数据。可能值得一试?

// some code so I can post a link to JS fiddle

【讨论】:

移除base64编码后,似乎很有魅力!

以上是关于PhoneGap SVG 作为 iOS 上的 data-uri的主要内容,如果未能解决你的问题,请参考以下文章

SVG 作为 MIXIN 中的背景图像通过 SASS 变量设置颜色

iOS 上的 Phonegap 构建/地理定位

iOS 上的 PhoneGap 网络信息插件问题

iOS 上的 Phonegap 触发自定义事件

Phonegap + jQueryMobile + iOS 上的 PushNotifications

iPhone - iOS5:phonegap 上的地理位置