briangonzalez/jquery.pep.js

constrainTo parent and scaling

Closed this issue · 0 comments

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;