function - 我正在使用 fullpage.js 并想隐藏小屏幕的导航选项(最大宽度:700px)
问题描述
这是调用 fullpage.js 并设置选项的脚本:
<script>
new fullpage('#fullpage', {
//options here
autoScrolling: true,
scrollHorizontally: true,
navigation: true,
});
</script>
因此,当视口小于 700 像素时,我想让导航为假
我试过这个但没有用
function myFunction(x) {
if (x.matches) { // If media query matches
fullpage('#fullpage', { navigation: true,
});
} else {
fullpage('#fullpage', { navigation: false,
});
}
}
var x = window.matchMedia("(max-width: 700px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes
谢谢
解决方案
为什么不使用普通的 CSS 媒体查询?
@media screen and (max-height: 700px){
#fp-nav{
display: none;
}
}
推荐阅读
- sql - 当我有多个结果时,为什么这个 powershell 代码只返回一个结果?
- laravel - Laravel 5.8 .env.testing 文件不工作
- ios - UIPanGestureRecognizer 弹出 UIViewController
- git - 在 Github 上更改拉取请求的基本分支时会删除哪些提交?
- r - 使用基于组的汇总值创建新变量
- html - 下载为 TSV 时更改谷歌电子表格的文件名
- c++ - 优雅的 C++ 代码:如何使用 while 循环和条件语句编写更高效的代码
- java - 使用 AtlasMap 将 xml 转换为 json
- r - 强制 R 将字符串评估为列名
- javascript - expressjs 服务器上的 HTML 按钮运行 node.js 脚本