Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sylink
Apr 17, 2004

Is it possible to dynamically change the size of a canvas in javascript instead of specifying like below?

code:

 <body onload="draw()">
   <canvas id="canvas" width="600" height="400"></canvas>
 </body>
</html>

Adbot
ADBOT LOVES YOU

Sylink
Apr 17, 2004

I got it working but not to my liking, I realized that the canvas is a bitmap so resizing makes it look like rear end.

Sylink fucked around with this message at 03:22 on Apr 2, 2009

Sylink
Apr 17, 2004

Is there an easy way to find the index of an object in an array of objects in JS? I am trying to avoid an extra library to add in but if I have to I will (looking at underscore).

For example
code:

var foo = [{test:1,some:3,thing:4},{test:2,some:5,thing:6}];

How do I search for a specific index such as what is the index of {test:2,some:5,thing:6}? (which we know is 1 by looking).

IndexOf does not work for this correctly it would seem.

Sylink
Apr 17, 2004

Yah I had to do a loop, would prefer a pre-made function, but I guess I will roll my own out of this, still easier than the standard functions.

code:
var test = [{name:"bob",id:5},{name:"dan",id:6}];

var check = {name:"dan",id:6};
for (var i = 0; i < test.length; i++) {
    var temp = _.isEqual(test[i],check); 
    if (temp === true) {
        alert(i);
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply