Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        3年前关闭。
                                                                                            
                
        
我正在使用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' +
    ')';


小提琴:https://jsfiddle.net/jmz20uhy/

关于javascript - 您如何切换background:url的? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40597907/

10-17 02:57