用JavaScript仿PS裡的羽化效果代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用JavaScript防PS裡的羽化效果代碼 - www.jb51.net</title>
</head>
<body onload=setValues()>
<center>
<SCRIPT language=JavaScript>
<!-- Beginning of JavaScript -
var x,y
var marginbottom
var marginleft=0
var margintop=0
var marginright
var cliptop
var clipbottom
var clipleft
var clipright
var clippoints
var ballheight=150
var ballwidth=150
var imageheight=525
var imagewidth=457
var tempo=25
var stepx=12
var stepy=6
var timer
function setValues() {
if (document.all) {
marginbottom = imageheight-ballheight
marginright = imagewidth-ballwidth
document.all.ball.style.posLeft=randommaker(400)
document.all.ball.style.posTop=0
document.all.textcontent.style.posLeft=0
document.all.textcontent.style.posTop=0
document.all.ball.style.filter="alpha(opacity=0,finishopacity=100,style=2,startX=0px,startY=0px,finishX=100px,finishY=100px)"
moveball()
}
}
// randomfunction
function randommaker(range) {
rand=Math.floor(range*Math.random())
return rand
}
function moveball() {
checkposition()
if (document.all) {
document.all.ball.style.posLeft+=stepx
document.all.ball.style.posTop+=stepy
cliptop=document.all.ball.style.posTop
clipbottom=cliptop+ballheight
clipleft=document.all.ball.style.posLeft
clipright=clipleft+ballwidth
clippoints="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
document.all.textcontent.style.clip=clippoints
timer=setTimeout("moveball()",tempo)
}
}
function checkposition() {
if (document.all) {
if (document.all.ball.style.posLeft>=marginright) {
stepx=stepx*-1
document.all.ball.style.posLeft-=10
}
if (document.all.ball.style.posLeft<=marginleft) {
stepx=stepx*-1
document.all.ball.style.posLeft+=10
}
if (document.all.ball.style.posTop>=marginbottom) {
stepy=stepy*-1
document.all.ball.style.posTop-=10
}
if (document.all.ball.style.posTop<=margintop) {
stepy=stepy*-1
document.all.ball.style.posTop+=10
}
}
}
// - End of JavaScript - -->
</SCRIPT>
<span id=textcontent style="LEFT: -5000px; POSITION: absolute; TOP: -2000px"><IMG border=0 src="http://files.jb51.net/upload/201112/20111220011256875.jpg"> </span>
<span id=ball style="BACKGROUND-COLOR: white; HEIGHT: 150px; POSITION: absolute; TOP: -50px; WIDTH: 150px"></span>
</center>
</body>
</html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.