0

I'm trying to create two draggable sidebars with snap.js. The right sidebar isn't displayed, instead of it there is the left sidebar.

codepen demo: http://codepen.io/anon/pen/pjREZg

var snapper = new Snap({
     element: document.getElementById('content'),
     hyperextensible: false
});

var addEvent = function addEvent(element, eventName, func) {
    if (element.addEventListener) {
        return element.addEventListener(eventName, func, false);
    } else if (element.attachEvent) {
        return element.attachEvent("on" + eventName, func);
    }
};

addEvent(document.getElementById('open-left'), 'click', function(){
    if( snapper.state().state=="left" ){
       snapper.close('left');
    }else {
        snapper.open('left');
    }
});

$('#open-right').click(function(){
    if( snapper.state().state=="right" ){
       snapper.close('right');
    }else {
        snapper.open('right');
    }
});

/* Prevent Safari opening links when viewing as a Mobile App */
(function (a, b, c) {
    if(c in b && b[c]) {
        var d, e = a.location,
            f = /^(a|html)$/i;
        a.addEventListener("click", function (a) {
            d = a.target;
            while(!f.test(d.nodeName)) d = d.parentNode;
            "href" in d && (d.href.indexOf("http") || ~d.href.indexOf(e.host)) && (a.preventDefault(), e.href = d.href)
        }, !1)
    }
})(document, window.navigator, "standalone");
filippo90
  • 367
  • 2
  • 3
  • 15

2 Answers2

0

You are trying to call a single sidebar from both buttons.

You need to create another sidebar instance that you can control with the right button like so:

var snapper2 = new Snap({
     element: document.getElementById('content'),
     hyperextensible: false
});

$('#open-right').click(function(){
    if( snapper2.state().state=="right" ){
       snapper2.close('right');
   }else {
       snapper2.open('right');
   }
});
Matt O'Connell
  • 287
  • 3
  • 14
0

Sorry about that, I've resolved it one minute after posting the question... after a night of trouble.

Just removed a display none from .snapjs-right .snap-drawer-right

So easy that I didn't notice it

filippo90
  • 367
  • 2
  • 3
  • 15