So I have been trying to figure this out on my own for a little while. Figured I would ask here since I always seem to get some great responses.
So. I want to know the dimensions of the browser window minus 25%. I have a two column layout and i want to use tim thumb or regular attributes (just to test). to make sure that I get the correct height and width of the area I want to show on an image.
25% | rest of the page (this is where the image is). the height I have no problem since I can do .height() - 240 (which I know because of my CSS. my question is the width.
Here is what I have so far, but cant seem to make it work.
var bg_width = $(window).width() * .025;
var bg_height = $(window).height() - 240;
$(".backgrounds img").each(function(bg_width,bg_height){
$(this).attr('width',bg_width);
$(this).attr('height',' + bg_height + ');
});
Anyone see anything wrong with this or why it doesnt work?
So I have been trying to figure this out on my own for a little while. Figured I would ask here since I always seem to get some great responses.
So. I want to know the dimensions of the browser window minus 25%. I have a two column layout and i want to use tim thumb or regular attributes (just to test). to make sure that I get the correct height and width of the area I want to show on an image.
25% | rest of the page (this is where the image is). the height I have no problem since I can do .height() - 240 (which I know because of my CSS. my question is the width.
Here is what I have so far, but cant seem to make it work.
var bg_width = $(window).width() * .025;
var bg_height = $(window).height() - 240;
$(".backgrounds img").each(function(bg_width,bg_height){
$(this).attr('width',bg_width);
$(this).attr('height',' + bg_height + ');
});
Anyone see anything wrong with this or why it doesnt work?
Share Improve this question asked Feb 2, 2012 at 15:49 rchiribogarchiriboga 1872 silver badges16 bronze badges 2- 9 0.025 isn't 25%. Should be 0.25 – Urbycoz Commented Feb 2, 2012 at 15:51
-
If you want the width - 25% then it should be
var bg_width = $(window).width() * 0.75;
– Reinstate Monica Cellio Commented Feb 2, 2012 at 15:54
4 Answers
Reset to default 7.025 is not 25%
you want .25
you are off by a decimal
anyhow, that will give you 25%, but the width of the browser minus 25% is really 75% so you REALLY want
myWidth = $(window).width() * .75
Assuming that $(window).width()
is returning the correct width of the browser window, then
var bg_width = $(window).width() * .025;
Isn't going to give you the the browser width - 25%:
So. I want to know the dimensions of the browser window minus 25%
To do that you want:
var bg_width = $(window).width() * 0.75;
var bg_width = $(window).width() * .75;
var bg_height = $(window).height() - 240;
$(".backgrounds img").each(function(bg_width,bg_height){
$(this).attr('width', bg_width);
$(this).attr('height', bg_height);
});
note that for 75% it's $(window).width() * .75;
Isn't it a typo:
$(this).attr('height',' + bg_height + ');
Should be:
$(this).attr('height', bg_height);