jquery - Javascript Parameters Function on Many Events -
i'm trying implement hammer.js swipe pages (like book) , did it. problem works
var idhammer1 = document.getelementbyid("pagehoja1") //var hammertime = new hammer(myelement, hammeroptionspan); var objhammer1 = new hammer(idhammer1); objhammer1.on('panleft panright', function(ev) { //dblog("obj1 - gsceneactual antes: " + gsceneactual + " // x: " + ev.center.x + " y: " + ev.center.y); if (ev.type==='panleft') { if (!(gsceneactual===2)) { gsceneactual = 2; $(":mobile-pagecontainer").pagecontainer("change", "#pagehoja2", { transition: "slide", reverse: false}); } } else if (ev.type==='panright') { } });
but doesn't:
var fswipe1 = function(ev) { //dblog("obj1 - gsceneactual antes: " + gsceneactual + " // x: " + ev.center.x + " y: " + ev.center.y); if (ev.type==='panleft') { if (!(gsceneactual===2)) { gsceneactual = 2; $(":mobile-pagecontainer").pagecontainer("change", "#pagehoja2", { transition: "slide", reverse: false}); } } else if (ev.type==='panright') { } } var idhammer1 = document.getelementbyid("pagehoja1") //var hammertime = new hammer(myelement, hammeroptionspan); var objhammer1 = new hammer(idhammer1); objhammer1.on('panleft panright', fswipe1(ev))
and don't work
function fswipe1(ev) { //dblog("obj1 - gsceneactual antes: " + gsceneactual + " // x: " + ev.center.x + " y: " + ev.center.y); if (ev.type==='panleft') { if (!(gsceneactual===2)) { gsceneactual = 2; $(":mobile-pagecontainer").pagecontainer("change", "#pagehoja2", { transition: "slide", reverse: false}); } } else if (ev.type==='panright') { } }
and since need add event many pages (variable #) cant hardcode it... how can make variable inside cycle?
thanks!
ah, without knowing extent of errors, see:
objhammer1.on('panleft panright', fswipe1(ev));
here, rendering function automatically, want use closure function not rendered until event gets hit. i'm not sure ev
represents, if event object, should work:
objhammer1.on('panleft panright', fswipe1);
where doing passing in function want callback , automatically call function , pass event
object first parameter.
a few other things notice:
- make sure include javascript library hammer
- make sure
gsceneactual
defined before evaluated @gsceneactual===2
- make sure jquery library included
Comments
Post a Comment