Pregunta

I've found this line of code somewhere using firebug and I know you need to put something where I've put the 3... behind parseFloat, but I have no idea what. It works when I fill in a random number but the width is never the correct one and want to use it on several pages with photographs so it's always the correct size.

script type="text/javascript">
var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
$(document).ready(function(){
var scaledwidth = ((parseFloat(...)*($(window).height()/4000))+50).toFixed(0);
if (badBrowser) {
$('#container img').css('height',$(window).height()+'px');
}
$('#container').css('width',scaledwidth+'px');
imageresize();
});
jQuery(window).resize(function() {
var scaledwidth = ((parseFloat(...)*($(window).height()/4000))+50).toFixed(0);
if (badBrowser) {
$('#container img').css('height',$(window).height()+'px');
}
$('#container').css('width',scaledwidth+'px');
imageresize();
});
function imageresize() {
var height = $(window).height();
if ((height) > 1340){
var quality='1440';
} else if((height) > 980) {
var quality='1080';
} else if((height) > 680) {
var quality='720';
} else if((height) > 480) {
var quality='640';
} else {
var quality='320';
}

}
</script>   

Thanks in advance!

¿Fue útil?

Solución

It looks to me like the value you need to put there depends on the sum of the widths of all the images; so you can't just pick a value that works for all pages.

On the other hand, it also seems like a bad solution to the problem of keeping the images next to each other. Why set the width of the container? If you just ensure white-space doesn't wrap then all the images should sit next to each other without worrying about the container's width.

#container
{
    white-space: nowrap; /* keep images on the same line */
    font-size: 0;        /* removes whitespace between images */
}

http://jsfiddle.net/f8y4Z/

From the javascript, we now only need the imageresize() (provided we use it to set different quality source images), and trigger it on ready and resize; no magic numbers required.

(For backwards compatibility with browsers that don't or poorly support white-space, you could use <nobr></nobr>)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top