briangonzalez / jquery.pep.js

👟 Pep, a lightweight plugin for kinetic drag on mobile/desktop
http://pep.briangonzalez.org
1.3k stars 177 forks source link

constrainTo parent and scaling #178

Closed marcoancona closed 7 years ago

marcoancona commented 8 years ago

If constrainTo is set to 'parent' and the parent is scaled with transform: scale(), the constraints are broken: http://codepen.io/marcoancona/pen/ZQYGVN

Problem is that in

Pep.prototype.handleConstraint = function(dx, dy, accountForTranslation) {
    var pos               = this.$el.position();

pos has new scaled position while container and element width are the original ones.

Suggested fix:

  Pep.prototype.handleConstraint = function(dx, dy, accountForTranslation) {
    var pos               = this.$el.position();
    this.pos.x            = pos.left / this.scale;
    this.pos.y            = pos.top / this.scale;