javascript - Swipe and click compability in Web/Mobile -
-i have little problem swipe effect (scrollleft) , "onclick" functionality.
-so want achieve when scroll touchpad verticaly on image (actually have 2 images in container) have second image, same thing happen click on 1 of 2 buttons (left or right).
-my problem here tried 2 states differentiate when i'm on second image or when i'm on first image. here loop function me "swipe" image touchpad:
var s = 0; var pas = 10; var max = widthimg1; var state1 = 0; var stateimg = "front"; function loop() { var bl = document.getelementbyid('imgbuttonleft'); var br = document.getelementbyid('imgbuttonright'); if (s != max) { s = wrapimage1.scrollleft; wrapimage1.scrollleft += pas; if (state1 == 0) { console.log("first"); $("#backimg").addclass('select'); $("#frontimg").removeclass('select'); $('.imgtitlefront').hide(); $('.imgtitleback').show(); bl.style.opacity = "1.0"; br.style.opacity = "0.5"; } if (state1 == 1) { console.log("second"); $("#frontimg").addclass('select'); $("#backimg").removeclass('select'); $('.imgtitleback').hide(); $('.imgtitlefront').show(); bl.style.opacity = "0.5"; br.style.opacity = "1.0"; } } else { console.log("three"); pas = pas * -1; if (state1 == 0) { console.log("four"); state1 = 1; } else if (state1 == 1) { console.log("five"); state1 = 0; } if (max == widthimg1) { console.log("six"); max = 0; } else { console.log("seven"); max = widthimg1; } } }
here html :
<div class="wraphidden" id="co"> <div class="wrapimage" id="wrapimage1" onscroll="loop()"> <div class="wrapbigsize" id="wrapbig"> <p class="imgbutton left" id="imgbuttonleft" onclick="pucetransition(true)"></p> <img class="myimage" id="myimagefront" src="imgfront"> <p class="imgbutton right" id="imgbuttonright" onclick="pucetransition(false)"></p> <img class="myimage second" id="myimageback" src="imgback"> </div> </div> </div>
and here "onclick" function :
function pucetransition(front) { if (front) { if (stateimg == "back") { stateimg = "front"; state1 = 0; loop(); } } else { if (stateimg == "front") { stateimg = "back"; state1 = 1; loop(); } }
}
so codes, problem think code don't know state on , don't know why.
Comments
Post a Comment