Skip to content Skip to sidebar Skip to footer

How To Fix The Position Of Mask In Snapsvg.js?

Here is js code: var cv = Snap('#cv').attr({height: '100%', width: '100%'}); var mskHide = cv.rect().attr({height: '100%', width: '100%', left:0, top:0, fill: '#666'}); var mskSho

Solution 1:

You could basically do what you have in the 2nd codepen.

var cv = Snap('#cv').attr({height: '100%', width: '100%'});

var mskHide = cv.rect().attr({height: '100%', width: '100%', left:0, top:0, fill: '#666'});
var mskShow = cv.circle(200, 200, 150).attr({fill: '#fff'});
var mskG = cv.group(mskHide, mskShow);


var bg = cv.circle(200, 200, 150).attr({fill: '#aaa'});

var customImg = cv.image('http://placehold.it/500/990000').attr({mask: mskG });


customImg.drag( myDrag );
function myDrag(dx,dy,x,y) {
  customImg.attr({ x: dx, y: dy })
}

codepen

If you want a different drag from the example shown to include stored start drag location, you would amend it something like the following...

customImg.attr({ x: 0, y: 0})

var move = function(dx,dy) {
this.attr({
      x: +this.data('ox') + +dx,
      y: +this.data('oy') + +dy
    })
} 

var start = function(x,y) {
  this.data('ox', this.attr('x'));
  this.data('oy', this.attr('y'));
}

var end = function(x,y) {}  

customImg.drag( move, start, end )

codepen


Post a Comment for "How To Fix The Position Of Mask In Snapsvg.js?"