Make your homepage ever-changing

Source: Internet
Author: User
Tags filter date define functions return
Many netizens send e-mail to ask me: "How every time go to your homepage, see pictures are not the same, do you always change the picture?" "God, I don't have that much money to pay for the phone bill." I just used a little javascript trick to do a random picture. Its HTML source code is:

<! Random Picture Start >

< script language=″javascript″>

<!--

Imglink=new Date ();

var Thisimg=http://www.webjx.com/htmldata/2005-02-24/″1.jpg″;

if (Imglink.getseconds () < Si) {var thisimg=″2.jpg″;}

if (Imglink.getseconds () <) {var Thisimg=″3.jpg″}

if (Imglink.getseconds () <) {var Thisimg=″4.jpg″;}

if (Imglink.getseconds () <) {var Thisimg=″5.jpg″}

if (Imglink.getseconds () <) {var Thisimg=″6.jpg″}

if (Imglink.getseconds () <) {var Thisimg=″7.jpg″;}

if (Imglink.getseconds () < 9) {var Thisimg=″8.jpg″;}

document.write (″< img src=″+thisimg+″border=0 Alt=″ Every time you open this page, you see a different picture! ″>″);

-->

</script >

<! Random Picture End >

In this example, 8 images are set and placed in the same directory as the Web page. When the browser opens this page, read the time from the computer immediately and choose a different picture based on the number of seconds.

We also often complain that the pictures inserted in the Web page and the background of the page can not be very well fused together, if the picture around a circle of dim transition Color that much better! The use of Photoshop to make pictures of course can achieve this effect. In fact, there is a better way: in the Web page with CSS filter to achieve!

< P Style=″line-height:0pt;filter:glow

(color=#ffffff,strength=36);height:auto;position:relative;padding:21pt″>

< img src=http://www.webjx.com/htmldata/2005-02-24/″1.jpg″border=0 >

</p >

where "color=#ffffff" is the color that defines the shadow, "strength=36" defines the width of the shadow. How, the picture is not have "hazy month, bird hazy" feeling?

If you do not like the "warm and romantic" homepage type, there is also a "magic bold" pie--

Add the following in < head >
< start defining color-changing functions >

< script language=″javascript″>

<!--hide

function Randomnumber (max)//Defining random functions

{var today=new Date ();

var num=math.round (Math.Abs (Math.sin (Today.gettime ()) *1000))%max+1;return num;

function Makearray (n)

{this.length=0;for (var i=1;i< n;i++) This[i]=0;return this;} function ChangeColor ()

{cleartimeout ();

Linkarray=new Makearray (10); Define 10 common colors with Linkarray array

Linkarray[1]=″#ff0000″;

Linkarray[2]=″#ffff00″;

Linkarray[3]=″#00ff00″;

Linkarray[4]=″#0000ff″;

Linkarray[5]=″#8000ff″;

Linkarray[6]=″#ff00ff″;

Linkarray[7]=″#004000″;

Linkarray[8]=″#808000″;

Linkarray[9]=″#ff8000″;

Linkarray[10]=″#ff0000″;

Document.bgcolor= (Linkarray[randomnumber (10)]); Using random function to choose one of 10 colors as the background color of a Web page

SetTimeout (″changecolor () ″,1000); Set the clock to change the background color once per second

return;}

-->

</script >

< define color function End >

Then call the ChangeColor () function in to:< the Body onload=″javascript:changecolor () ″>

The background color of the page changes once every second, cool enough?

If put "document.bgcolor= (Linkarray[randomnumber (10)]);" A sentence of "bgcolor" replaced by "Fgcolor", can also achieve the page text constantly changing color. In addition, you can define the time period of discoloration by yourself, changing "settimeout (″changecolor () ″,1000);" In the "1000" can be.

(Hebei Desert Eagle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.