I'm trying to create a gradient with 3 images that will scale based on browser window width.
It's simple enough, one image on the left that's the start a 1x1 pixel to stretch to whatever the needed width is and one on the right to end it.
CSS:
JS:Code:#container { width: 80%; margin: auto; } #container #gradient { width: 100%; } #container #gradient img { height: 1px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; }
HTML:Code:function init() { if (Math.floor(window.innerWidth * .8) > 263 * 2 + 1) { document.getElementById("middle").style.width = Math.floor(window.innerWidth * .8 - (263 * 2)) + "px"; } }
The images two cap images are 263x1. It always sends the last image to a new line, I tried tweaking and setting the multiplier to .78 vs .8 caused it to work but that's not accurate so the bigger the resolution the bigger the gap.Code:<div id="container"> <div id="gradient"><img src="gradient1.png"><img src="middle.png" id="middle"><img src="gradient2.png"></div> </div>
I know my code might be a lil messy :P I wanna make it work before I worry about all that, is it just a discrepancy between the interpreting of innerWidth and CSS width?
Thanks
twQ



Reply With Quote

Bookmarks