Skip to content

getPosition returns NaN #4

@nvitas

Description

@nvitas

Thanks for implementing the horizontal scrolling I really appreciate it. It works great and I'll be using it in an iPad app I'm currently writing.

When calling the getPosition function currently it returns a NaN. The problem is that an object is being multiplied by -1

i.e. this.getPosition() returns an object {x:0,y:0} and then it is multiplied by -1

getPosition: function() {
var a = [];
this.each(function() {
a.push(-this.getPosition()); <-- problem here
});
return a;
},

I fiddled around with it for a little bit and a simple fix is to get the object first and then multiply each value inside it by -1.

Here's the code:

getPosition: function() {
var a;
this.each(function() {
a = this.getPosition();
a.x = -a.x;
a.y = -a.y;
});
return a;
},

This way when you call:

var position = $('nav').touchScroll('getPosition');

then you can get both the vertical and horizontal values by saying

position.x // for horizontal
position.y // for vertical

Again, thanks for making the horizontal version of this plugin public and hopefully the code above helps make it even better.

Nik

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions