Skip to content

Prevent moves image outside the screen #582

Answered by anton-red
anton-red asked this question in Q&A
Discussion options

You must be logged in to vote

If someone looking for the answer it's helped me.
You should use "move" method like example below

or read this #429

var maxOffsetPercentage = 0.9;

move: function (event) {

  var viewerData = viewer.viewerData;
  var imageData = viewer.imageData;
  var maxOffsetHorizontal = viewerData.width * maxOffsetPercentage;
  var maxOffsetVertical = viewerData.height * maxOffsetPercentage;
  var detail = event.detail;
  var left = detail.x;
  var top = detail.y;
  var right = viewerData.width - (left + imageData.width);
  var bottom = viewerData.height - (top + imageData.height);
 
  if (
 // Move left
 (detail.x < detail.oldX && right > 0 && right > maxOffsetHorizontal)
   
  // Move right
  || (det…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anton-red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant