Resize Raster according to screen size in PaperJS -
i resize raster (image) when resize canvas via paperjs. i'm using following codes:
var last_point = view.center; var img = new raster('images/test.png', view.center); img.onload = function() { resizeimg(); } function onresize(event) { view.scrollby(last_point.subtract(view.center)); last_point = view.center; resizeimg(); } function resizeimg() { var width = paper.view.size.width; var scale = (width / img.width) * 0.75; img.scale(scale); }
however, once going through resizeimg()
function, image gone (commented function out make image re-appear).
what did miss in function? i guess it's simple mistake in calculation
an object's width referenced bounds.width
property, not width
alone.
function resizeimg() { var width = paper.view.size.width; var scale = (width / img.bounds.width) * 0.75; img.scale(scale); }
Comments
Post a Comment