본문 바로가기
Javascript

배경이미지 랜덤으로 바꾸기

by 포샵질 2017. 2. 1.

<SCRIPT Language="JavaScript">
<!-- 
var gaTe
function gateway(){
  var onRotate = new Array()

onRotate[0] = '<img src="g1/stop_watch_07.jpg" width="512" height="149" alt="PSA[ play 120" border="0">'
onRotate[1] = '<img src="g1/hyper.jpg" width="512" height="149" alt="Hyper Flight" border="0">'
onRotate[2] = '<img src="g1/presto.jpg" width="512" height="149" alt="Presto" border="0">'
onRotate[3] = '<img src="g1/shox.jpg" width="512" height="149" alt="Nike Shox BB4" border="0">'
onRotate[4] = '<img src="g1/craze.jpg" width="512" height="149" alt="Presto Craze" border="0">'

  
  onRotate[5] = onRotate[0] 
  gaTe = Math.round(Math.random() * 5)
  return onRotate[gaTe]
  }
  //-->
</SCRIPT>

이거나 혹은
<SCRIPT Language="JavaScript">
<!-- 
var curindex=0

var randomimages=new Array()

// 아래처럼 보여줄 이미지들을 설정 하세요

        randomimages[0]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_01.gif"
        randomimages[1]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_02.gif"
        randomimages[2]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_03.gif"
        randomimages[3]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_04.gif"
        randomimages[4]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_05.gif"
        randomimages[5]="http://pimg.hanmail.net/hanmail/s_img/pcp/service/puzzle/n_level_06.gif"

var preload=new Array()

for (n=0;n<randomimages.length;n++)
{
        preload[n]=new Image()
        preload[n].src=randomimages[n]
}

document.write('<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">')

function rotateimage()
{

if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){
curindex=curindex==0? 1 : curindex-1
}
else
curindex=tempindex

        document.images.defaultimage.src=randomimages[curindex]
}
  //-->
</SCRIPT>

'Javascript' 카테고리의 다른 글

좌우배경이미지다른페이지제작  (0) 2017.02.01
마우스 오른쪽 막기  (0) 2017.02.01
새로운창 위치 조정하기  (0) 2017.01.24
스크롤 따라다니는 레이어  (0) 2017.01.24
팝업창과 윈도우 컨트롤  (0) 2017.01.24