peachananr / onepage-scroll

Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin
http://peachananr.github.io/onepage-scroll/Demo/demo.html
9.54k stars 2.07k forks source link

Broken link handling on touch devices (got a fix) #47

Open wallride opened 10 years ago

wallride commented 10 years ago

Now this patch fixes problem when doesn't work.

function touchstart(event) {
  var touches = event.originalEvent.touches;
  var touchedObject = touches[0].target;
  if (touchedObject.nodeName=='A'){
      $(touchedObject).click();
      return 1;
  }
  if(!(
        typeof($._data(touchedObject, "events")) !== 'undefined' 
        && $._data(touchedObject, "events").click != null
    )){
    startX = touches[0].pageX;
    startY = touches[0].pageY;
    $this.bind('touchmove', touchmove);
  }
  event.preventDefault();
}
wallride commented 10 years ago

same problem can appear with other clickable elements (such as input, select, etc.). I haven't tested it yet. The solution can be the same.

raykanani commented 10 years ago

This doesn't seem to fix the problem on Apple devices or with input elements on all touch devices.

wallride commented 10 years ago

yep! this particular code fixes only [a href] links. I couldn't find better solution than the checking touch-target object if it's supposed to be clickable or interactive. So for other elements you shoud go way like that.

sephiran commented 10 years ago

I don't get it. How should I use your code? Im a JS noobie, so please excuse my stupid question :) .With onclick on the a href link like so: onclick="touchstart(event)"? Thanks

sephiran commented 10 years ago

I have a solution now which works for me. $('.touchme').bind('touchstart click', function(){ href = $(this).attr("href"); window.location.assign(href); });

wallride commented 10 years ago

That code is a fixed part of the original library. Just find the line with "function touchstart(event)" and replace the function.

So you wont have to bind all the links and use additional classes at all

sephiran commented 10 years ago

Okay thank you wallride. I implemented your solution but figured out that the scrolling with the responsive update doesnt work anymore on the ios simulator. In chrome on mac it works fine. I think I'll just use my "workaround" to use both on ios.