javascript - Clicking anywhere on the page causes nav with class affix-top to change to class affix
问题描述
I have a web page I need to style for a client. I cannot change the header they created. My navbar is a div with id="nav" class="affix-top" and is fine until I click anywhere on the page. When I click anywhere the class in my navbar changes to "affix", if I click again it change to "affix-top" and displays again.
see below
//I've added some styles to keep navbar from disappearing when scrolling:
#nav.affix-top {
position: relative;
top: 0px;
}
#nav.affix {
position: fixed;
top: 101px;
}
//It works ok.
//But when I click on the page, or a button or anything the navbar disappears
//behind the header due to the class changing. I tried this, but it did not
//work.
$(document.body).click( function() {
$('#nav').removeClass('affix');
$('#nav').addClass('affix-top');
});
I expect my navbar to remain unchanged when clicking on the page. Thank you.
解决方案
推荐阅读
- java - Spring MVC 响应标头:为什么在我返回新的 ResponseEntity 时在参数 HttpServletResponse 上设置标头有效?
- xml - 如何使用 Powershell 从 XML 循环和读取所有必需的属性值
- python-3.x - 模拟异步事件循环的内部时钟
- favicon - 在 Mattermost 网站中设置 favicon 的配置
- razor - 引导列到行
- php - 用另一个替换从 mssql 数据库读取的文本中的字符。(php)
- javascript - vuejs 根据条件选择选项更改
- c# - 嵌套的 CoVariance 会变成逆变吗?
- django - Django 表单向导将数据保存到 PostgreSQL
- java - JaCoCo 未根据源文件生成覆盖率报告 - 方法名称不可点击