Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turn off slider in portrait mode? #41

Open
thomasSolyan opened this issue Jun 20, 2014 · 0 comments
Open

turn off slider in portrait mode? #41

thomasSolyan opened this issue Jun 20, 2014 · 0 comments

Comments

@thomasSolyan
Copy link

I am trying to turn off the slider and remove all its css when orientation is 0 (portrait) or when:
window.addEventListener("resize", function() {
if ( (document.documentElement.offsetWidth < document.documentElement.offsetHeight) || (window.matchMedia("screen and (orientation: portrait)").matches) ) {

// turn off slider and reset original css

} else {
  slidr.create('panels-container', {
    controls: 'none',
    fade: true,
    overflow: true,
    keyboard: true,
    touch: true
  }).start();

}

Is there a way to do this? I have tried to .removeAttr('style data-style') but I need to return to original css before slider was attached.

here is my hack solution which uses a reload (not-good):

window.onload = function() {
var smLoad = window.sessionStorage.getItem('smLoad'),
bgLoad = window.sessionStorage.getItem('bgLoad'),

  smallLoad = function() {
    if (smLoad && smLoad === 'false' || !smLoad) {
      console.log('small');
      location.reload();
    }
  },

  bigLoad = function() {
    if (bgLoad && bgLoad === 'false' || !bgLoad) {
      console.log('big')
      location.reload();
    }
  };

if ( (document.documentElement.offsetWidth < document.documentElement.offsetHeight) || (window.matchMedia("screen and (orientation: portrait)").matches) ) {
console.log('portrait');
slidr.create('panels-container').stop();
window.sessionStorage.setItem('smLoad', 'true');
window.sessionStorage.setItem('bgLoad', 'false');
} else if ( (document.documentElement.offsetWidth > document.documentElement.offsetHeight) || (window.matchMedia("screen and (orientation: landscape)").matches) ) {
console.log('landscape');
slidr.create('panels-container', {
controls: 'none',
fade: true,
overflow: true,
keyboard: true,
touch: true
}).start();
window.sessionStorage.setItem('bgLoad', 'true');
window.sessionStorage.setItem('smLoad', 'false');
}

window.addEventListener("resize", function() {
if ( (document.documentElement.offsetWidth < document.documentElement.offsetHeight) || (window.matchMedia("screen and (orientation: portrait)").matches) ) {
smallLoad();
} else if ( (document.documentElement.offsetWidth > document.documentElement.offsetHeight) || (window.matchMedia("screen and (orientation: landscape)").matches) ) {
bigLoad();
}
}, false);

window.addEventListener("orientationchange", function() {
var orientation = (window.orientation != undefined);
console.log('orientationChange ' + orientation);
if (orientation === 0) {
smallLoad();
}
if (orientation === -90 || orientation === 90) {
bigLoad();
}
}, false);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant