How to make a div increase or decrease using the touchmove?

Asked

Viewed 44 times

1

I’m trying to make a div open as the user drags his finger down, and make it close as he drags his finger up. I searched and saw that I can capture the touch of the user on the screen with the touch events, but I’m not able to make it work.

This is the code I’ve developed so far:

window.addEventListener('load', function(){
 
  var box2 = document.querySelector('#todo'),
    boxleft, 
    startx, 
    dist = 0,
    touchobj = null;
 
  box2.addEventListener('touchstart', function(e){
    touchobj = e.changedTouches[0];
    startx = parseInt(touchobj.clientX);
    e.preventDefault();
  }, false);
 
  box2.addEventListener('touchmove', function(e){
    document.querySelector("#d1").style.height = "100px";
    e.preventDefault();
  }, false);
 
}, false);
#todo {
  background-color: #550000;
  height: 300px;
  width: 100%;
}

#d1 {
  background-color: #555555;
  height: 50px;
  width: 100%;
}
<div id="todo">
  <div id="d1"></div>
</div>

  • What problem are you having? I tested it here and the code is working normally.

  • For forehead, open your project by chorme and simulate a window of mobile for Developer Tools

  • I’d like to make the div "#D1" rise as I drag my finger down... she’s not doing it =\

  • It’s working now, how strange!

  • to work, you must simulate a cell screen or use the cell phone itself.

  • I was pretending... but it didn’t work

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.