【发布时间】:2014-12-07 10:53:37
【问题描述】:
我需要实时启用/禁用 .js 插件。当用户重新调整他的浏览器窗口大小时,桌面版变为移动版。问题是我需要禁用一些 javascript (fullpage.js) 并添加一些 css。 如果您从头到尾重新加载页面或在 PC 上使用全屏窗口,则没有问题。问题是:如何在宽度
将此函数添加到body onresize 事件(不重新加载没有结果):
function checkWidth() {
if($(window).width() <= 760 ){
$('#menu-header-button').click(function(){
$('#navigation').toggleClass('navbar-v');
$('#logo-mobile').toggleClass('visible');
$('#menu-header-button').addClass('disabled');
setTimeout(function(){
$('#menu-header-button').removeClass('disabled');
}, 500);
});
} else if($(window).width() > 760 ){
$('#fullpage').fullpage({
menu: '#menu',
anchors: ['firstPage', 'secondPage', '3rdPage', '4thPage'],
css3: true,
afterLoad: function(anchorLink, index){
if( anchorLink == 'firstPage'){
$('#navigation').removeClass('navbar-v');
}
},
onLeave: function(index, nextIndex, direction){
setTimeout(function(){
$('#navigation').addClass('navbar-v');
}, 500);
}
});
}
}
这只是有时有效:
$(window).onresize= checkWidth();
function checkWidth() {
if($(window).width() == 761 ){
location.reload(true);
}
//...
}
这根本不起作用:
$(window).onresize= checkWidth();
function delayCheckWidth(){
setTimeout(function(){
checkWidth();
}, 50); //I thought some delay time can be useful here
}
function checkWidth() {
if($(window).width() == 761 ){
location.reload(true);
}
//...
}
我查看的相关主题:
- Throttling
- How to disable / Enable plugins?
- Enable / Disable JavaScript code
- How to disable / Enable plugins?
- Enable and disable jquery knob dynamically
- Disable and enable jQuery context menu
- 还有很多其他的。
与实时无关,也没有什么有趣/有用的。
你有什么建议吗?也许我不需要这样做?
【问题讨论】:
标签: javascript jquery html css fullpage.js