473,748 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple backgrounds

I can set/change a background with:

document.getEle mentById("photo div").style.bac kground =
"#282828 url(../img/pict_1.jpg)";

How do I set/change multiple backgrounds using javascript?
Aug 25 '08 #1
6 3094
On Aug 25, 8:37 pm, Johan <por...@can.spa mwrote:
I can set/change a background with:

document.getEle mentById("photo div").style.bac kground =
"#282828 url(../img/pict_1.jpg)";

How do I set/change multiple backgrounds using javascript?
Repeat that line for each div?
Aug 26 '08 #2
SAM
Johan a écrit :
I can set/change a background with:

document.getEle mentById("photo div").style.bac kground =
"#282828 url(../img/pict_1.jpg)";

How do I set/change multiple backgrounds using javascript?
The easiest way is to use a class in the body tag

document.body.c lassName = 'back_1';
document.body.c lassName = 'back_2';

CSS :
=====
..back_1 { background: yellow; }
..back_1 div { background: url(../img/pict_1.jpg) }
..back_1 div.special { background: #282828 }
..back_2 { background: white; }
..back_1 div { background: url(../img/pict_2.jpg) }
/* and so on */
Or using a loop on elements to change :

var D = document.getEle mementsByTagNam e('DIV');
for(var i=0, n = D.length; i<n; i++)
D[i].style.backgrou nd="#282828 url(../img/pict_1.jpg)";
You can also use alternative style sheets

--
sm
Aug 26 '08 #3
SAM wrote:
Johan a écrit :
>I can set/change a background with:

document.getEl ementById("phot odiv").style.ba ckground =
"#282828 url(../img/pict_1.jpg)";

How do I set/change multiple backgrounds using javascript?


The easiest way is to use a class in the body tag

document.body.c lassName = 'back_1';
document.body.c lassName = 'back_2';

CSS :
=====
.back_1 { background: yellow; }
.back_1 div { background: url(../img/pict_1.jpg) }
.back_1 div.special { background: #282828 }
.back_2 { background: white; }
.back_1 div { background: url(../img/pict_2.jpg) }
/* and so on */
Or using a loop on elements to change :

var D = document.getEle mementsByTagNam e('DIV');
for(var i=0, n = D.length; i<n; i++)
D[i].style.backgrou nd="#282828 url(../img/pict_1.jpg)";
You can also use alternative style sheets
Thank for your suggestions.

However, my question is how I can set/change multiple backgrounds with
javascript. I think I wasn't clear but they should appear in one div.
You can set them with css in this way:
#show {
background-image:
url("images/pict_1.jpg"),
url("images/pict_2.jpg"),
url("images/pict_3.jpg"),
url("images/pict_4.jpg");
background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
background-position: top left, top right, bottom right, bottom left;
}
Note: it's one sigle div.

Now I want to change them with javascript.
Aug 26 '08 #4
Laser Lips wrote:
On Aug 25, 8:37 pm, Johan <por...@can.spa mwrote:
>>I can set/change a background with:

document.getE lementById("pho todiv").style.b ackground =
"#282828 url(../img/pict_1.jpg)";

How do I set/change multiple backgrounds using javascript?


Repeat that line for each div?
They should appear in one div.
Aug 26 '08 #5
On 26 Aug., 16:06, Johan <por...@can.spa mwrote:
SAM wrote:
You can set them with css in this way:
#show {
* *background-image:
* * *url("images/pict_1.jpg"),
* * *url("images/pict_2.jpg"),
* * *url("images/pict_3.jpg"),
* * *url("images/pict_4.jpg");
* *background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
* *background-position: top left, top right, bottom right, bottom left;}
You are aware, that this is CSS3 and is currently supported only by
Safari and KHTML-based browsers?
Now I want to change them with javascript.
Basically by combining the what you posted in your original post and
here:

var theDivStyle = document.getEle mentById("photo div").style;
theDivStyle.bac kgroundImage = 'url("images/pict_1.jpg"), url("images/
pict_2.jpg"), url("images/pict_3.jpg"), url("images/pict_4.jpg")';
theDivStyle.bac kgroundRepeat = 'no-repeat, no-repeat, no-repeat, no-
repeat';
theDivStyle.bac kgroundPosition = 'top left, top right, bottom right,
bottom left';

Or by using the shorthand property as in CSS

theDivStyle.bac kground = 'url("images/pict_1.jpg") no-repeat top left,
url("images/pict_2.jpg") no-repeat top right, ...'; /* abbreviated */

(watch the line breaks)

Robin
Aug 26 '08 #6
SAM
Johan a écrit :
>
However, my question is how I can set/change multiple backgrounds with
javascript. I think I wasn't clear but they should appear in one div.

You can set them with css in this way:
??? in which navigator can you have this kind of CSS ?
(my Fx told me it is not good)
#show {
background-image:
url("images/pict_1.jpg"),
url("images/pict_2.jpg"),
url("images/pict_3.jpg"),
url("images/pict_4.jpg");
background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
background-position: top left, top right, bottom right, bottom left;
}
Note: it's one sigle div.
and there is no image in background.
Now I want to change them with javascript.
Why for ?
because you want to correct the error ?
CSS :
=====
#show { background: url(images/pict1.jpg) no-repeat top left #ffc; }
#show.p_tr { background-position: top right; }
#show.p_br { background-position: bottom right; }
#show.p_bl { background-position: bottom left; }
#show.i_l { background-image: url(images/pict2.jpg) }
#show.i_2 { background-image: url(images/pict3.jpg) }
#show.i_3 { background-image: url(images/pict4.jpg) }

JS :
====
function chang(img, pos) {
var d = document.getEle mentById('show' );
d.className = img+' '+pos;
}

HTML:
=====

<div id="show" style="height:6 00px">
<p><a href="javascrip t:chang('i_1',' p_tr')">
pict #2 top right</a>
<p><a href="javascrip t:chang('i_1',' p_br')">
pict #2 bottom right</a>
<p><a href="javascrip t:chang('i_2',' p_bl')">
pict #3 bottom left</a>
<p><a href="javascrip t:chang('','')" >
original pict and position</a>
</div>

======== soluce 2 =============

CSS :
=====
#show { background: url(images/pict1.jpg) no-repeat top left #ffc; }

JS :
====
function chang(img, pos) {
var d = document.getEle mentById('show' ).style;
d.backgroundPos ition = pos;
d.backgroundIma ge = 'url(images/'+img+'.jpg)';
}

HTML :
======
<div id="show" style="height:6 00px">
<p><a href="javascrip t:chang('pict2' ,'top right')">
pict #2 top right</a>
<p><a href="javascrip t:chang('pict2' ,'bottom right')">
pict #2 bottom right</a>
<p><a href="javascrip t:chang('pict3' ,'bottom left')">
pict #3 bottom left</a>
<p><a href="javascrip t:chang('pict1' ,'top left')">
original pict and position</a>
</div>

--
sm
Aug 26 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2689
by: RoDzZzZ | last post by:
when i try print (ctrl +p) my webpage, my printer not print the backgrounds and bgcolors of my tables.... what i need make to show the backgrounds and bgcolors in my paper when the user print the page? thankzzz
2
1522
by: Greg Locke | last post by:
Hi All I am programming MFC Visual C++ using Microsoft Visual Studio.net 2003 under Windows XP professional. I have developed some bitmaps as graphic overlays for buttons. I had trouble finding a colour for the bitmap backgrounds from the standard pallette that matched the xp beige standard button color. Managed to do this by creating one from RGB numbers in another editor, but I suspect it shouldn't have been this awkward. I now also...
6
2361
by: MLH | last post by:
I have a logo image that I can paste into MS Paint as an image with clear background. Think of the logo as a black circle in a white, rectangular background. When I paste into Paint, the white back- ground can be made "clear" so it does NOT overwrite other image data when I'm pasting into an existing picture. Just the circle would appear after the paste is made. However, when I try to accomplish the same thing with an Access 97 form,...
0
1385
by: ghadley_00 | last post by:
Hi, Have created 2 seperate reports that have different images as backgrounds. Would like to have both pages print out as 1 print job (so duplex printer will make each report page on opposite sides of page) - I tried placeing both reports as subreports in a single report (lets call it SuperReport), but in that case the image backgrounds get overwritten by whatever image is set as the background for SuperReport. Any suggestions on how I...
6
1432
by: Rik Brooks | last post by:
I'm developing Web Applications with C# code behind. I have found that, because of the particular nuances of my company, I am stuck with positioning the items on the page with tables. No problem with that though. The problem is that some of the controls on the screen are displayed with yellow backgrounds and I can't figure out how to change that to white (as the others are). Nothing I do seems to make a difference. Could someone give...
1
3431
gregerly
by: gregerly | last post by:
I'm a total flash / actionscript newbie. I have a question about how to create a flash background as seen here: Adobe MAX I don't expect a detailed explanation. I'm just looking for some info on how they create the particle effects and moving backgrounds. It looks really cool but I wouldn't know where to start to create something like that. Thanks, Greg
1
1686
by: alice | last post by:
I'm trying to have a background image in a div, then have several divs within that div that have black backgrounds. The problem I'm finding is that in Firefox and Safari, the first background image does not show through on the other divs, it's as if the black background takes over, and the space around it reverts to the body background, not the background image of the containing div. Is there a way around this?
1
2220
by: matturn | last post by:
Is there any way to get IE7 to render the whole viewpoint without forcing a page reload? If you set a DIV to 100% wide or high, and give it a background; that background will not be rendered if it isn't on the screen when the page loads. Scrolling to non-visible parts of the page will reveal huge blank areas. Is there any technique to fix this, causing the backgrounds to appear like Firefox et al?
2
1830
duhcoolies
by: duhcoolies | last post by:
I have a table-cell (width=!00%) with a background (BG1), and within this table-cell I have another table-cell (again width=100%) with another background (BG2). BG1 needs to be tiled horizontally only and I have achieved this. BG2 (small image) needs to be located at the bottom left corner and I dont want to tile this... I have achieved this as well. I achieved both backgrounds with CSS by adding the CSS styles to the td tag of each table-cell....
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.