javascript - Adding background img if screen resolution width >1028 -



javascript - Adding background img if screen resolution width >1028 -

hi guys,

i'm new javascript. have pretty simple script wrote add together background image if screen resolution width bigger 1028px.

unfortunately, after trying (on computer, 800x600 resolution), doesn't work.

i'm not looking stretch image, add together if screen resolution width bigger or equal 1024.

here code:

<script language="javascript"> <!-- document.write('<style type="text/css">div#container_header_body {background-image:url(\''); if (screen.width<1024) { document.write('none;'); } else { document.write('images/mmmgirl.png'); } document.write('\');</style>'); //--> </script> <link rel="stylesheet" type="text/css" href="stylesheet.css" />

can give me insight i'm doing wrong?

thanks much. i've learned lot place.

- - andrew

try this jsfiddle:

var screenwidth = screen.width, container = document.getelementbyid('container_header_body'); console.log(screenwidth); if (screenwidth > 1024) { container.style.backgroundimage = 'url(http://oddanimals.com/images/lime-cat.jpg)'; } else { container.style.backgroundimage = 'none'; }

javascript background image screen-resolution

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -