dtdsbakn210537 2015-07-20 12:32
浏览 41

使用淡入淡出的php / js始终在顶部菜单上更改

I'd like to make 1 "always on top" menu on a website. I'ts different when you are actually on top,and if you scroll down the menu will change. My problem is when the menu is changing its dissaperaing then i get the new 1. I want the changing with fading,but i have no idea how i could do this. (example fading always on top changing menu: http://www.aquariushand.hu/ ) Here's what i have:

HTML:

<div id="navi">
<div id="menu" class="default">
<img align="left" width="15%" height="100%" src="pics/a.jpeg"/>
    <ul>
        <li><a href="#">Rólunk</a></li>
        <li><a href="#">Lakóknak</a></li>
        <li><a href="#">GYIK</a></li>
        <li><a href="#">Kapcsolat</a></li>

    </ul>
</div><!-- close menu -->

CSS:

#menu {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #426d9c), color-stop(40%, #0f67a1), color-stop(100%, #1384d1));
background: -moz-linear-gradient(top, #426d9c, #0f67a1, #1384d1);

border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;

line-height: 20px;
text-align: center;
margin: 0 auto;
padding: 0;
 z-index: 99;
}
.default {
width: 100%;
height: 50px;

box-shadow: 0 5px 20px #888;
-webkit-box-shadow: 0 5px 20px #888;
-moz-box-shadow: 0 5px 20px #888;
}

.fixed {
position: fixed;
top: -5px;
left: 0;
width: 100%;
height: 5%;

box-shadow: 0 0 40px #222;
-webkit-box-shadow: 0 0 40px #222;
-moz-box-shadow: 0 0 40px #222;
}

JS:

$(function(){

var menu = $('#menu'),
    pos = menu.offset();

    $(window).scroll(function(){
        if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
            menu.fadeOut('fast', function(){
                $(this).removeClass('default').addClass('fixed').fadeIn('fast');
            });
        } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
            menu.fadeOut('fast', function(){
                $(this).removeClass('fixed').addClass('default').fadeIn('fast');
            });
        }
    });

});

I want something like like on the example page.

  • 写回答

1条回答 默认 最新

  • dongzhen7108 2015-07-20 12:38
    关注

    On your CSS you should add position and give it fixed value like

    #menu {
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #426d9c), color-stop(40%, #0f67a1), color-stop(100%, #1384d1));
    background: -moz-linear-gradient(top, #426d9c, #0f67a1, #1384d1);
    
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    
    line-height: 20px;
    text-align: center;
    margin: 0 auto;
    padding: 0;
      position:fixed;
     z-index: 99;
    }
    .default {
    width: 100%;
    height: 50px;
    
    box-shadow: 0 5px 20px #888;
    -webkit-box-shadow: 0 5px 20px #888;
    -moz-box-shadow: 0 5px 20px #888;
    }

    Anyway I don't see where you are using .fixed class

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?