jQuery - scroll behaviour on mobile with touchmove

0 votes
398 views
added Jun 27, 2019 in jQuery by LC Marshal Captain (25,790 points)
//on click buttton bind the touchmove 
$(shareBtn).on('click', function() {
  $('body').bind('touchmove',function(e){
  e.preventDefault();
  var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
    elm = $(this).offset(),
    x = touch.pageX - elm.left,
    y = touch.pageY - elm.top;
  });
  // $('body').bind('touchmove', function(e){
  //   e.preventDefault();
  // });
  $('body').css({overflow: 'hidden'});
  $(shareBox).addClass('in');
  $('.share-news-content > img.ico').attr('src', closeIco);
  $(this).addClass('on-click');
});

// else unbind
$('body').css({'overflow': 'auto'}).unbind('touchmove');

 

1 Response

0 votes
responded Jul 7, 2019 by LC Marshal Captain (25,790 points)
// if passing elements

function highlightme(x, y) {
    $('.element').each(function() {
      // check the flag area
      if (!(
          x <= $(this).offset().left || x >= $(this).offset().left + $(this).outerWidth() ||
          y <= $(this).offset().top  || y >= $(this).offset().top + $(this).outerHeight()
      )) {

        $('.element').removeClass('highlighted');
        $(this).addClass('highlighted');
      }
    });
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...