[英]How to disable OverlayScrollbars when window width equal 600px?
I use overlayScrollbars to create a <nav></nav>
.我使用overlayScrollbars创建一个<nav></nav>
。
When window width less than 600px, then navbar go left like sidebar.当 window 宽度小于 600px 时,导航栏 go 像侧边栏一样离开。
<ul>
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
</ul>
and create a js file and add this line:并创建一个 js 文件并添加以下行:
$('ul').overlayScrollbars({ });
now when my widnow width less than 600px, overlayScrollbars worke fine but when my window width bigger than 600px, overlayScrollbars still work and element width is like sidebar.现在当我的窗口宽度小于 600px 时,overlayScrollbars 工作正常,但是当我的 window 宽度大于 600px 时,overlayScrollbars 仍然有效并且元素宽度就像侧边栏。
How can I disable overlayScrollbars() when my window width bigger than 600px?当我的 window 宽度大于 600px 时,如何禁用 overlayScrollbars()?
HTML HTML
<ul id="test">
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
</ul>
JQuery JQuery
So you get it onload
--------------------
if($(window).width() < 600) {
var instance = OverlayScrollbars(document.getElementById("test"), {});
}
$(window).resize(function() {
var instance = OverlayScrollbars(document.getElementById("test"), {});
if ($(window).width() > 600) {
instance.destroy();
}
});
You can use the $(window).height(); $(window).width();
您可以使用$(window).height(); $(window).width();
$(window).height(); $(window).width();
to check the width and height of page and then enable or disable stuffs with a basic if else
function.检查页面的宽度和高度,然后使用基本的if else
function 启用或禁用东西。
You need to:你需要:
.destroy()
them.将覆盖实例存储为变量,以便您可以.destroy()
它们。.destroy()
and recreation of new instances to an onresize
event, with the same check as when the page loads.将.destroy()
和新实例的重新创建附加到onresize
事件,与页面加载时进行相同的检查。Here's an example of how to store and destroy with jQuery.这是一个如何使用 jQuery 进行存储和销毁的示例。
//initializes plugin and stores the instance into a variable
var instance = $('ul').overlayScrollbars({ }).overlayScrollbars();
instance.destroy();
Use Media Query to hide elements from any screen!使用媒体查询从任何屏幕隐藏元素!
Try it:试试看:
<style>
@media (min-width:600px){
.yourOverlayElement{ display:none; }
}
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.