Ir para conteúdo
Fórum Script Brasil
  • 0

BG Randomico


Tarragô

Pergunta

Boa tarde gente,

Sou novo por aqui e não sei nada de programação, por isso me inscrevi, para aprender - rs

Estou tentando desenvolver meu site para poder vender meus serviços que são de design.

Espero que vocês possam me ajudar.

Uma coisa interessante que gostaria de aplicar em meu site seria um Bg randomico como o gmail faz.

O Bg muda a cada refresh de página e o bg é auto ajustavel aos diferentes formatos.

Para isso peguei os seguintes códigos:

BG Radom

<script language="JavaScript">

<!-- Activate cloaking device

var randnum = Math.random();

var inum = 4;

// Change this number to the number of images you are using.

var rand1 = Math.round(randnum * (inum-1)) + 1;

images = new Array

images[1] = "zebra.jpg"

images[2] = "tiler3.jpg"

images[3] = "wicker3.jpg"

images[4] = "aaa4.jpg"

// Ensure you have an array item for every image you are using.

var image = images[rand1]

// Deactivate cloaking device -->

</script>

Use this code in place of the <body> tag:

<script language="JavaScript">

<!-- Activate cloaking device

document.write('<body background="' + image + '" text="white">')

// Deactivate cloaking device -->

</script>

E BG Stretch

<style type="text/css">

html, body {

height: 100%;

margin: 0;

padding: 0;

}

</style>

Add the image you want as the background as the first element of the web page, and give it the id of bg:

<body>

<img src="bgimage.jpg" alt="background image" id="bg" />

</body>

Position the background image so that it's fixed at the top left and is 100% wide and 100% in height. Add this to your style sheet:

img#bg {

position:fixed;

top:0;

left:0;

width:100%;

height:100%;

}

Add all your content to the page inside of a <div> called "content". Add this below the image:

<div id="content">All your content here - including headers, paragraphs, etc.</div>

Note: it's interesting to look at your page now. The image should display stretched out, but your content is completely missing. Why? Because the background image is 100% in height, and the content division is after the image in the flow of the document — most browsers won't display it.

Position your content so that it's relative and has a z-index of 1. This will bring it above the background image in standards-compliant browsers. Add this to your style sheet:

#content {

position:relative;

z-index:1;

}

But you're not done. Internet Explorer 6 isn't standards compliant and still has some problems. There are many ways to hide the CSS from every browser but IE 6, but the easiest (and least dangerous) is to use conditional comments. Put the following after your style sheet:

...

</style>

<!--[if IE 6]>

<![endif]-->

Inside the highlighted comment, add another style sheet with some styles to get IE 6 to play nice:

<!--[if IE 6]>

<style type="text/css">

html { overflow-y: hidden; }

body { overflow-y: auto; }

img#bg { position:absolute; z-index:-1; }

#content { position:static; }

</style>

<![endif]-->

Mas como disse sou novo e não consegui por para funcionar.

Tentei colocar nos lugares sugeridos e nada.

Alguém tem alguma sugestão?

Obrigado.

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

cara você pode da uma olhada sobre PHP e alguns comandos basico para entender melhor a linguagem dai agente pode ver uma funçãozinha so para ler e fzr o randomico tpw na minha cabeca agora veio algo com um banco de dados por exemplo

banco de dados site com a tabela background e com um campo chamado bg do tipo int

beleza agora tu pode fazer um select nessa tabela e cria um while onde atribui uma pequena funçãozinhaa

$i recebe o valor do campo bg da tabela e faz o MOD dele assim se for tipo MOD de 0 é = a 0 então o BG é 1 e é dado um update na tabela para ela passar de 0 para 1...

proxima pessoa que entrar ao site vai fzr a mesmo coisa mas ai na tabela vai estar 1 então MOD de 1 é = a 0.5 sendo assim c for diferente de 0 o BG é 2

c entraram 19 pessoas quando entra a 20 vai fazer o MOD de 20 que é 0 então o BG é 1 sendo assim te afirmo que em numeros pares da 0 e impares 1 ...

so para tu entende isso o MOD pega o resto da divisão exemplo

10 dividor por 2 = a 5 beleza

11 divididor por 2 = a 5.5 .. sendo assim ele pega o 0.5 + o 0.5 = 1

quando o numero é par n tem resto sendo assim o MOD de um numero par é 0 ...

mas isso não vem ao caso é so para vocÊ saber o que estudar para ter uma ideia de como fazer... isso tudo é logica e n é complicado =]

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...