2015-09-28 76 views
2

我在这个网站上使用了一个响应式导航插件导航我目前正在使用,并且缩小导航的标签位于JavaScript文件中,我想将它作为菜单按钮而不是文本。Javascript img src变体?

有什么办法可以做到吗? (我已经改变了我想成为一个图像的一部分,“这就是我想成为的图像”,在下面的代码)

var ResponsiveNav = function (el, options) { 
    var i; 

    /** 
    * Default options 
    * @type {Object} 
    */ 
    this.options = { 
     animate: true,     // Boolean: Use CSS3 transitions, true or false 
     transition: 284,     // Integer: Speed of the transition, in milliseconds 
     label: "THIS IS WHAT I WANT TO BE AN IMAGE",     // String: Label for the navigation toggle 
     insert: "before",     // String: Insert the toggle before or after the navigation 
     customToggle: "",     // Selector: Specify the ID of a custom toggle 
     closeOnNavClick: false,   // Boolean: Close the navigation when one of the links are clicked 
     openPos: "relative",    // String: Position of the opened nav, relative or static 
     navClass: "nav-collapse",   // String: Default CSS class. If changed, you need to edit the CSS too! 
     navActiveClass: "js-nav-active", // String: Class that is added to <html> element when nav is active 
     jsClass: "js",     // String: 'JS enabled' class which is added to <html> element 
     init: function(){},    // Function: Init callback 
     open: function(){},    // Function: Open callback 
     close: function(){}    // Function: Close callback 
    }; 

非常感谢。

+0

我相信你想存储图像的路径,然后在定义图像的src属性时引用该对象。 – Nocturno

+0

什么是插件? –

+0

嗨,该插件是http://responsive-nav.com/ –

回答

0

添加图片到页面的HTML,给它一个ID,然后将ID添加到customToggle选项(参见“myImg”下面的例子)

例如

<img src="myimg.png" id="myImg"> 
<nav class="nav-collapse"> 
    <ul> 
    <li><a href="#">Home</a></li> 
    <li><a href="#">About</a></li> 
    <li><a href="#">Projects</a></li> 
    <li><a href="#">Contact</a></li> 
    </ul> 
</nav> 

var nav = responsiveNav(".nav-collapse", { // Selector 
    animate: true, // Boolean: Use CSS3 transitions, true or false 
    transition: 284, // Integer: Speed of the transition, in milliseconds 
    label: "Menu", // String: Label for the navigation toggle 
    insert: "before", // String: Insert the toggle before or after the navigation 
    customToggle: "myImg", // Selector: Specify the ID of a custom toggle 
    closeOnNavClick: false, // Boolean: Close the navigation when one of the links are clicked 
    openPos: "relative", // String: Position of the opened nav, relative or static 
    navClass: "nav-collapse", // String: Default CSS class. If changed, you need to edit the CSS too! 
    navActiveClass: "js-nav-active", // String: Class that is added to element when nav is active 
    jsClass: "js", // String: 'JS enabled' class which is added to element 
    init: function(){}, // Function: Init callback 
    open: function(){}, // Function: Open callback 
    close: function(){} // Function: Close callback 
}); 
+0

有没有什么办法可以使图像消失时按下菜单按钮?所以只是导航显示 –

+0

被按下时,您可以添加一个事件侦听器,你的形象来改变它的风格:的document.getElementById(“myImg”)的addEventListener(“点击”,函数(){ this.style.display ='none'; }); –