I need to enable/disable .js plugins in real time. When user re-sizes his browser window, desktop version becomes mobile. The thing is I need to disable some javascript (fullpage.js) and add some css. And there is no problems if you reload the page or use full-screen window on your pc, from start to the end. The question is : how can I disable fullpage.js on width < 800 ? I've tried this things :
Added this function to body onresize
event (no result without reloading) :
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);
}
});
}
}
This was working only sometimes :
$(window).onresize= checkWidth();
function checkWidth() {
if($(window).width() == 761 ){
location.reload(true);
}
//...
}
This wasn't working at all :
$(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);
}
//...
}
Related themes i checked out :
- 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
- Lots of others.
Nothing about real time or nothing interesting/helpful .
Do you have any advises? Maybe i don't need to go this exactly this way ?