<DIV ID="lay1" > <BR> この不透明度は変化しません。<BR> <IMG SRC="usagi.gif"> </DIV>
<STYLE TYPE="text/css"> <!-- #lay1 { filter:alpha(opacity=60); background-color:white; color:#606090; width:320px; padding:10px; } --> </STYLE>
onMouseover="setTransparent(this,100)" onMouseout ="setTransparent(this,50)"
<HTML> <HEAD> <TITLE>半透明処理</TITLE> <STYLE TYPE="text/css"> <!-- #lay1 { filter:alpha(opacity=60); background-color:white; color:#606090; width:320px; padding:10px; } --> </STYLE> <SCRIPT Language="JavaScript"> <!-- function setTransparent(theLay,n) { theLay.filters["alpha"].opacity = n; } // --> </SCRIPT> </HEAD> <BODY BACKGROUND="bg.jpg"> <DIV ID="lay1" onMouseover="setTransparent(this,100)" onMouseout ="setTransparent(this,60)" > ■半透明処理<BR><BR> ここのオブジェクト上にマウスを乗せると半透明だったレイヤーが くっきり表示されます。<BR> <IMG SRC="usagi.gif"> </DIV> <BR><BR> <DIV ID="lay1" > <BR> この不透明度は変化しません。<BR> <IMG SRC="usagi.gif"> </DIV> </BODY> </HTML>
pStr += str.charAt(count++);で、取り出した文字列を pStr に追加し、count の値を1加えます。str.length は str の文字の長さを示す属性です。最後の文字を表示したら、初期化を行い、1000ミリ秒お休みします。
<BODY onLoad="out1Char()">
<HTML> <HEAD> <TITLE>順次表示</TITLE> <STYLE TYPE="text/css"> <!-- #seq {width:250px; font-family: 'MS ゴシック'; font-size:20pt;padding:10px; background-color:#FFFFDF;} --> </STYLE> <SCRIPT Language="JavaScript"> <!-- str = "もうすぐ夏休み "; pStr = ""; count = 0; function out1Char() { if(count < str.length ){ pStr += str.charAt(count++); seq.innerText = pStr; delay=300; if(count==str.length) {//初期化 count=0; seq.innerText=""; pStr=""; delay=1000; } setTimeout("out1Char()",delay); } } // --> </SCRIPT> </HEAD> <BODY onLoad="out1Char()"> 1文字づつ文章を表示します<BR><BR> <DIV ID = "seq"></DIV> </BODY> </HTML>
document.onmousemove = moveChar;とします。
#myChar { position:absolute; top:100px; left:100px; } <IMG SRC="usagi.gif" ID="myChar" >スクリプトで、次のように posLeft を変更すると、画像の左の座標は cx に移動します。
myChar.style.posLeft= cx;
<HTML> <HEAD> <TITLE>マウスに近づくキャラクタ</TITLE> <STYLE TYPE="text/css"> <!-- #myChar { position:absolute; top:100px; left:100px; } --></STYLE> <SCRIPT Language="JavaScript"> <!-- function moveChar() { var cx = myChar.style.posLeft; var cy = myChar.style.posTop; var dt = dist(cx,cy,event.x,event.y); if(dt > 100){ cx = cx*0.98 + event.x*0.02; cy = cy*0.98 + event.y*0.02; }; myChar.style.posLeft= cx; myChar.style.posTop = cy; } function dist(ax,ay,bx,by)//距離を計算 { return (ax-bx)*(ax-bx)+(ay-by)*(ay-by); } document.onmousemove = moveChar;//マウス移動イベント // --> </SCRIPT> </HEAD> <BODY BGCOLOR="white"> マウスに近づくキャラクタ<BR> <IMG SRC="usagi.gif" ID="myChar" > </BODY> </HTML>このスクリプトの動作は、ここから確認できます。マウスを移動したときのみ、キャラが移動しますから、マウスを急に移動すると、キャラをついてきません。