当前位置:首页 > 网页特效 > 导航菜单 >

背景滑动的菜单-Fancy Menu滑动菜单演示

时间:2013-12-19 08:50 来源:互联网 作者:源码搜藏 收藏 推荐

运行代码 保存代码 复制代码 提示:您可以先修改部分代码再运行,保存代码功能在Firefox下无效。
  • 这是FancyMenu的菜单示例,我只是简单的整理了一下代码,本菜单调用了Mootools,是一个与jquery同样优秀的前端开发插件,用它实现的菜单动画效果同样流畅。本菜单在鼠标移上去的时候,菜单项的背景滑动到鼠标的位置,导航菜单的外部样式调成成了圆角,更圆润了些,也漂亮了许多,对mootools.js有兴趣的可参见这个范例代码。
  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Fancy Menu背景滑动菜单[www.codesocang.com]</title>
    <style>
    #fancymenu{PADDING-RIGHT: 15px;PADDING-LEFT: 15px;BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/bg.gif) no-repeat 50% top;PADDING-BOTTOM: 15px;MARGIN: 10px 0px;OVERFLOW: hidden;WIDTH: 421px;PADDING-TOP: 15px;POSITION: relative;HEIGHT: 29px}
    #pictureselect{POSITION: relative;HEIGHT: 1%}
    #fancymenu UL{PADDING-RIGHT: 0px;PADDING-LEFT: 0px;PADDING-BOTTOM: 0px;MARGIN: 0px;PADDING-TOP: 0px}
    #pictureselect{PADDING-RIGHT: 0px;PADDING-LEFT: 0px;PADDING-BOTTOM: 0px;MARGIN: 0px;PADDING-TOP: 0px}
    #fancymenu UL LI{FLOAT: left;LIST-STYLE-TYPE: none}
    #pictureselect LI{FLOAT: left;LIST-STYLE-TYPE: none}
    #fancymenu UL LI A{DISPLAY: block;Z-INDEX: 10;FLOAT: left;OVERFLOW: hidden;TEXT-INDENT: -500em;POSITION: relative;HEIGHT: 30px}
    #pictureselect LI A{DISPLAY: block;Z-INDEX: 10;FLOAT: left;OVERFLOW: hidden;TEXT-INDENT: -500em;POSITION: relative;HEIGHT: 30px}
    #pictureselect LI{HEIGHT: 54px}
    #pictureselect LI A{WIDTH: 62px;HEIGHT: 54px}
    #menu_home A{BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/menu_home.png) no-repeat center 50%;WIDTH: 59px}
    #menu_plantatree A{BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/menu_plantatree.png) no-repeat center 50%;WIDTH: 119px}
    #menu_travel A{BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/menu_travel.png) no-repeat center 50%;WIDTH: 70px}
    #menu_rideanelephant A{BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/menu_rideanelephant.png) no-repeat center 50%;WIDTH: 142px}
    #fancymenu LI.background{Z-INDEX: 8;BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/bg_menu_right.gif) no-repeat right top;VISIBILITY: hidden;POSITION: absolute}
    #fancymenu .background .left{BACKGROUND: url(http://www.codefans.net/jscss/demoimg/201312/bg_menu.gif) no-repeat left top;MARGIN-RIGHT: 9px;HEIGHT: 30px}
    </style>
    <script type="text/javascript" src="http://www.codefans.net/ajaxjs/mootools.v1.11.js"></script>
    <script type="text/javascript">
      var SlideList = new Class({
    initialize: function(menu, options) {
    this.setOptions(this.getOptions(), options);
    this.menu = $(menu), this.current = this.menu.getElement('li.current');
    this.menu.getElements('li').each(function(item){
    item.addEvent('mouseover', function(){ this.moveBg(item); }.bind(this));
    item.addEvent('mouseout', function(){ this.moveBg(this.current); }.bind(this));
    item.addEvent('click', function(event){ this.clickItem(event, item); }.bind(this));
    }.bind(this));
    this.back = new Element('li').addClass('background').adopt(new Element('div').addClass('left')).injectInside(this.menu);
    this.back.fx = this.back.effects(this.options);
    if(this.current) this.setCurrent(this.current);
    },
    setCurrent: function(el, effect){
    this.back.setStyles({left: (el.offsetLeft)+'px', width: (el.offsetWidth)+'px'});
    (effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1);
    this.current = el;
    },
    getOptions: function(){
    return {
    transition: Fx.Transitions.sineInOut,
    duration: 500, wait: false,
    onClick: Class.empty
    };
    },
    clickItem: function(event, item) {
    if(!this.current) this.setCurrent(item, true);
    this.current = item;
    this.options.onClick(new Event(event), item);
    },
    moveBg: function(to) {
    if(!this.current) return;
    this.back.fx.custom({
    left: [this.back.offsetLeft, to.offsetLeft],
    width: [this.back.offsetWidth, to.offsetWidth]
    });
    }
    });
    SlideList.implement(new Options);
    </script>
        <script type="text/javascript">
          window.addEvent('domready', function() {
    // orange menu demo
    if($('fancymenu'))
    FancyExample = new SlideList($E('ul', 'fancymenu'), {transition: Fx.Transitions.backOut, duration: 700, onClick: function(ev, item) { ev.stop(); }});
    // profile demo
    if($('pictureselect')) PictureSelect = new SlideList('pictureselect', { onClick: function(ev, item) { ev.stop(); } });
    });
    </script>
    </head>
    <body>
        <div id="fancymenu">
            <ul>
                <li class="current" id="menu_home"><a href="http://www.codesocang.com">主页</a></li>
                <li id="menu_plantatree"><a href="#">飞机</a></li>
                <li id="menu_travel"><a href="#">旅行</a></li>
                <li id="menu_rideanelephant"><a href="#">世界名著</a></li>
            </ul>
        </div>
    </body>
    </html>

由源码搜藏网整理,转载请注明出处https://www.codesocang.com/tx-daohang/6515.html

导航菜单下载排行

最新文章