【问题标题】:Sticky Menu Change Logo粘性菜单更改徽标
【发布时间】:2018-02-25 16:34:04
【问题描述】:

我正在开发一个有粘性菜单的网站,我需要做的是在其滚动时更改徽标并具有粘性标题。

标题是这样的

<header id="header" class="float-panel" data-top="0" data-scroll="100">

一旦我向下滚动,类就会变成固定的

<header id="header" class="float-panel  fixed" data-top="0" data-scroll="100">

一旦使用 css 或 jquery 修复徽标,我需要更改徽标,我可以定位,我尝试使用以下

if($("#header.float-panel").hasClass('fixed'))

这是徽标 div

<div class="logo"><!-- logo -->



    <a href="http://"><img src="Logo-Full_Pos.png" alt=""></a><h6 class="site-title"><a href="http://.com/" rel="home">g</a></h6>                           
                            </div>

谢谢

【问题讨论】:

  • 不需要脚本,在 CSS .float-panel.fixed { .... } 中使用即可。您可以将您的标志作为 bg-image,或使用 2 个元素,将 display: block 更改为 display: none
  • 不知道该怎么做,你能帮忙吗?
  • 我试着放了两个标志,这样我就可以玩一个隐藏和一个显示但失败了
  • 使用.float-panel .logo1{display: block} .float-panel.fixed .logo1{display: none} .float-panel .logo2{display: none} .float-panel.fixed .logo2{display: block} 明白了吗?
  • 成功了,非常感谢!

标签: javascript jquery html css


【解决方案1】:

这行代码: if($("#header.float-panel").hasClass('fixed')) 只会在加载时运行。您需要使用滚动事件:https://api.jquery.com/scroll/ 以确保在菜单固定时点击您的 if 语句。

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 2015-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多