image - fabricjs mouse events fail after setSrc() -


when changing selected canvas image larger image using setsrc(), mouse events not recognized on areas of new image lie outside of xy boundaries of original smaller image.

conversely, when changing selected canvas image smaller image, mouse events are recognized on areas outside of new image xy boundaries of original larger image.

in either case, once new image receive mouse click, things return normal entire image receives mouse events, no more, no less. also, controls appear in correct locations not clickable stated above.

is there way correct behavior complete visible image can receive mouse events?

http://jsfiddle.net/kamakalama/0ng18cas/10/

html

<body>     <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>     <button id="butt">change image</button>     <canvas style="border:1px solid silver;" width=500 height=400 id="c"></canvas> </body> 

javascript

$(document).ready(function() {   var canvas = new fabric.canvas('c',{backgroundcolor:"#ffffff"}); var bigimg="http://nonsuch30.com/yachtcards/images/cardbox-closed.jpg" var smallimg="http://nonsuch30.com/yachtcards/images/woodcrafter-thumb.jpg"      fabric.image.fromurl(smallimg, function (img) {                             canvas.add(img);     canvas.renderall();     img.settransformmatrix([ 1, 0, 0, 1, 0, 0])     canvas.setactiveobject(img)     })      $("#butt").click(function(){     img = canvas.getactiveobject()      if(img.getsrc()==smallimg){     img.setsrc(bigimg)     }else{     img.setsrc(smallimg)     }      settimeout(function(){         canvas.renderall()         canvas.setactiveobject(img)     }, 2000);      }); }); 

you're correct in using setcoords(), put , canvas.renderall() in setsrc() callback can remove settimeout() function call:

if (img.getsrc() == smallimg) {   img.setsrc(bigimg, function() {     canvas.renderall();     img.setcoords();   }); } else {   img.setsrc(smallimg, function() {     canvas.renderall();     img.setcoords();   }); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -