Reputation: 1
body {background-image: url('wallpaper.jpg'); background-size: cover;}
window.wallpaperPropertyListener = {
applyUserProperties: function(properties) {
if (properties.customimage) {
var customImageFile = 'file:///' + properties.customimage.value;
document.body.style.backgroundImage = `url('${customImageFile}')`;
}
},
};
this works if i set to img src instead of background-image. when i import image to user property, nothing changes. but when i remove it, background image (default one) disappears.
Upvotes: 0
Views: 64
Reputation: 61
In the case of the file:///
protocol, you should replace backslashes with forward slashes in the file path.
body {
background-size: cover;
}
window.wallpaperPropertyListener = {
applyUserProperties: function (properties) {
if (properties.customimage) {
var customImageFile = 'file:///' + properties.customimage.value.replace(/\\/g, '/');
document.body.style.backgroundImage = `url('${customImageFile}')`;
}
},
};
Upvotes: 0