Jump to content
  • Advertisement
Sign in to follow this  
gretty

Transfer code in ontouchstart into onmousedown

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I am programming a website mainly targetted at iOS Safari, but I also want it to respond to normal desktops.

So I have a need to make a button react to the events onmousedown onmouseup when on a desktop & for a button to react to ontouchstart ontouchend on iOS.

NOTE: I cannot do this(just register for both events):

<img id="button" onmousedown="this.src=''" onmouseup="this.src=''; doSomething();" ontouchstart="this.src=''" ontouchend="this.src=''"[/quote]

Whilst this will work on desktop, on iOS, the image src does not change, something to do with the order of events iOS mimics.

So I am trying to transfer the javascript in ontouchstart into onmousedown but I get the error "eles is undefined" when I press the button, the elements EXIST & have the correct ID's:


function enableDesktopGestures()
{
var eles = new Array(document.getElementById("topicIndex"),
document.getElementById("volumeToggle"),
document.getElementById("exitModuleBt"),
document.getElementById("prevBt"),
document.getElementById("nextBt"));

for (var i=0; i<eles.length; i++)
{
eles.addEventListener("mousedown", function() { eles.getAttribute("ontouchstart"); }, false);
eles.addEventListener("mouseup", function() { eles.getAttribute("ontouchend"); }, false);
}
}

// No error occurs with this but when I press the buttons nothing happens
function enableDesktopGestures()
{
var eles = new Array(document.getElementById("topicIndex"),
document.getElementById("volumeToggle"),
document.getElementById("exitModuleBt"),
document.getElementById("prevBt"),
document.getElementById("nextBt"));

for (var i=0; i<eles.length; i++)
{
var down = eles.getAttribute("ontouchstart");
var up = eles.getAttribute("ontouchend");
eles.onmousedown = function() { down; };
eles.onmouseup = function() { up; };
}
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!