如何切换 background:url?

How do you toggle background:url's?

我正在使用 Todd Moto 的 flaunt.js 进行导航,并希望在移动菜单显示和关闭时将汉堡包图像与另一图像切换,然后再返回。

演示在这里:

https://toddmotto.com/labs/flaunt-js

教程在这里:

https://toddmotto.com/flaunt-js-for-stylish-responsive-navigations-with-nested-click-to-reveal

是的,有很多方法可以更改 CSS 背景图片。可以直接设置。

示例:

HTML: <div id='my-box'></div> CSS:

#my-box {
    height: 518px;
    width: 800px;
}

JS:

document.querySelector('#my-box').style.backgroundImage =
    'url(' +
    'https://www.thebigduck.us/content/themes/big-duck/dist/images/dp03_v2.jpg' +
    ')';

Fiddle: https://jsfiddle.net/jmz20uhy/