用javascript实现文本的淡入淡出效果

主要是对RGB三色进行均匀地递增和递减,写起来比较简单:)

<html>
<head>
<title> Fade In and Fade Out </title>
<script type=”text/javascript”>
<!–

 var colorIn=’#0f0′;  // 淡入颜色
 var colorOut=’#0080c0′; // 淡出颜色
 var dur=5;    // 淡入淡出步数

 // 淡入淡出函数
 function fade(id,c1,c2){
  var txt=document.getElementById(id);
  var ri=sprRGB(c1,0),bi=sprRGB(c1,1),gi=sprRGB(c1,2);
  var ro=sprRGB(c2,0),bo=sprRGB(c2,1),go=sprRGB(c2,2);
  var st=0,sTimer = setInterval(function(){
   if(st!=dur){
    with(Math)var rs=floor((ri-ro)/(dur-st)),bs=floor((bi-bo)/(dur-st)),gs=floor((gi-go)/(dur-st));
    ro+=rs;bo+=bs;go+=gs;
    txt.style.color=’rgb(‘+ro+’,’+bo+’,’+go+’)’;
   }
   else clearInterval(sTimer);
   st++;
  },50);
 }

 // 分离RGB颜色 0:R | 1:G | 2:B
 function sprRGB(c,x){
  var p,l;
  c.length==4?l=1:l=2;
  p=x*l+1;
  c=c.substr(p,l)
  if(c.length==1)c+=c;
  return parseInt(c,16);
 }
//–>
</script>
</head>

<body>
<div id=”body” style=”background:#000;color:#0f0;width:500px;height:30px;font-size:18px;line-height:30px;text-align:center;font-weight:bold”>用javascript实现文本的淡入淡出效果</div>
<div>
<input type=”button” value=”Fade In” onclick=”fade(‘body’,colorOut,colorIn)” />
<input type=”button” value=”Fade Out” onclick=”fade(‘body’,colorIn,colorOut)” />
</div>
</body>
</html>

— EOF —

《用javascript实现文本的淡入淡出效果》有20个想法

  1. I simply desired to appreciate you once more. I’m not certain the things I might have accomplished in the absence of those thoughts discussed by you regarding my field. It seemed to be an absolute challenging crisis for me, nevertheless finding out this well-written form you processed the issue took me to leap with gladness. I’m just grateful for this work and then hope you really know what a great job you were carrying out training some other people all through a web site. Probably you’ve never come across any of us.

  2. I was looking at some of your posts on this website and I conceive this web site is really instructive! Keep putting up.

  3. I have observed that of all gipelris types of insurance, health insurance coverage is the most marked by controversy because of the turmoil between the insurance cover company’s necessity to remain adrift and the user’s need to have insurance plan. Insurance companies’ earnings on well being plans are low, so some businesses struggle to gain profits. Thanks for the suggestions you write about through this website.

  4. Kozłowski Radca Prawny Toruń to kancelaria prawna parająca się całościową obsługę klientów w obszarze prawa cywilnego, obsługi podmiotów gospodarczych, oraz pozyskiwania odszkodowań i zadośćuczynień w kraju i na obszarze Europy. Naszymi kontrahentami są zarówno osoby fizyczne jak również {makro|duże) i mikro spółki. Kozłowski Radca Prawny Toruń specjalizuje się również w pozwach zbiorowych. W ich ramach proponujemy naszym kontrahentom bezpłatne, profesjonalne spotkanie wstępne w w budynku naszej firmy. Kozłowski Radca Prawny Toruń zapewnia Państwu profesjonalną poradę w każdej sprawie.

  5. I’ve observed that in the world nowadays, video games would be the latest trend with children of all ages. There are times when it may be difficult to drag your kids away from the games. If you want the best of both worlds, there are various educational video games for kids. Thanks for your post.

  6. people a lot of time simply disk drive now there and additionally look ahead to sales person to express to a person the specialised data for one netbook,

  7. Wow, awesome weblog structure! How long have you been running a blog for? you made blogging look easy. The total look of your site is wonderful, as well as the content!

  8. F*ckin’ amazing issues here. I am very glad to peer your post. Thanks so much and i am having a look forward to contact you. Will you kindly drop me a e-mail?

  9. wonderful points altogether, you just gained a brand new reader. What would you suggest in regards to your post that you made some days ago? Any positive?

  10. The “shale revolution”, probably, seriously masters of the minds political figures and entrepreneurs of the world. Palm domination this area maintain Americans, but, apparently, there is a chance that other world soon to them to join. Naturally, has country where virtually is carried out receive shale gas in Russia, in particular, this endeavor the main interest of political and business elites looks sufficient skeptical. In this issue is not so much the factor financial profitability. Main circumstance that can to impact possibilities such industries as production of shale gas, – effects for environment.
    static electricity definition science

发表评论

电子邮件地址不会被公开。 必填项已用*标注