سؤال

I am getting a TypeError on the variable "pattern" and my script does not execute past the marked break point. I am using the JCanvas and JQuery and all dependencies are in place. What is the reason for the error. There is a similar implementation used here.

function drawMe(thumbUrl){
  function drawThumb(){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }

  var pattern = $("canvas").createPattern({
    source: thumbUrl,
    repeat: "repeat",
    load: drawThumb
  })

}

drawMe("http://placehold.it/100x100");
هل كانت مفيدة؟

المحلول

i think you need to change this

function drawThumb(){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }

to this

function drawThumb(pattern){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }

نصائح أخرى

I had this problem on Chrome. After restarting chrome it solved me the problem...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top