Clif
Clif

Reputation: 1

javascript variable in string

I'm struggling with this Javascript:

 width = screen.width * .75;
 height = screen.height * .75;

$(".colorbox").colorbox({
  width:"800px", 
  height:"600px", 
  iframe:true, 
  scrolling:false});

I am trying to put the values of width and height into the 800 and 600 spots, respectively.

Upvotes: 0

Views: 130

Answers (2)

Peter Olson
Peter Olson

Reputation: 142921

This is pretty straightforward to fix:

var width = screen.width * .75; 
var height = screen.height * .75;

$(".colorbox").colorbox({
  width: width, 
  height: height, 
  iframe: true, 
  scrolling: false});

(Just a side note, put var before your variable declarations, or else they will become global, perhaps unintentionally).

Upvotes: 3

Stephen
Stephen

Reputation: 3432

Colorbox actually supports specifying the widths as integers or with a unit..

So,

$(".colobox").colorbox({
  "width": width,
  "height": height
});

Upvotes: 1

Related Questions