一个幻灯片效果及其衍生的几种效果,不段补充中. 兼容浏览器:ie6.firefox1.3及其以上版本,主要是一个缓冲算法公式,及其禁用js的情况下,保持版面布局完好,正确.顺便贴一些运动计算公式.
JavaScript代码
- Fx.expoIn = function(pos){return Math.pow(2, 10 * (pos - 1))};
- Fx.expoOut = function(pos){return (-Math.pow(2, -10 * pos) + 1)};
- Fx.quadIn = function(pos){return Math.pow(pos, 2)};
- Fx.quadOut = function(pos){return -(pos)*(pos-2)};
- Fx.circOut = function(pos){return Math.sqrt(1 - Math.pow(pos-1,2))};
- Fx.circIn = function(pos){return -(Math.sqrt(1 - Math.pow(pos, 2)) - 1)};
- Fx.backIn = function(pos){return (pos)*pos*((2.7)*pos - 1.7)};
- Fx.backOut = function(pos){return ((pos-1)*(pos-1)*((2.7)*(pos-1) + 1.7) + 1)};
- Fx.sineOut = function(pos){return Math.sin(pos * (Math.PI/2))};
- Fx.sineIn = function(pos){return -Math.cos(pos * (Math.PI/2)) + 1};
- Fx.sineInOut = function(pos){return -(Math.cos(Math.PI*pos) - 1)/2};
- Fx.wobble = function(pos){return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5};
- Fx.pulse = function(pos){return (Math.floor(pos*10) % 2 == 0 ? (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10)))};
幻灯片甲的代码:
XML/HTML代码
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>幻灯片测试</title>
- <style type="text/css">
- <!--
- div{margin:0;padding:0}
- body {margin-left: 30px;margin-top: 30px;}
- .slide{float:left;position:relative}
- #img{width:441px;border:7px solid #156fe6; height:283px;overflow:hidden;}
- #img img{text-align:center;border:0px; vertical-align:top}
- #img a{display:block}
- #txt{position:absolute;bottom:7px;_bottom:6px;left:0px;opacity:0.7;-moz-opacity: 0.7;filter: alpha(opacity=70);width:421px;height:32px;overflow:hidden;text-align:left;background:#24211d;font-size:12px; padding:0 10px;margin-left:7px;line-height:32px;}
- #txt a{color:#fff;text-decoration:none;display:block}
- #btn{position:absolute;top:7px;right:17px;}
- #btn a{width:84px;height:51px;background:url(imgs/btnbg.gif);display:block;margin:10px 0}
- #btn a:hover{background:url(imgs/btna.gif)}
- #btn a:active{background:url(imgs/btned.gif)}
- #btn a.btna{background:url(imgs/btned.gif)}
- #btn img{margin:2px 0 0 7px;border:0px}
- -->
- </style></head>
- <body>
- <div class="slide">
- <div id="img"><a href="#" target="_blank"><img src="imgs/1.jpg"></a><a href="#" target="_blank"><img src="imgs/2.jpg"></a><a href="#" target="_blank"><img src="imgs/3.jpg"></a></div>
- <div class="link" id="btn"><a href="#" class="btna"><img src="imgs/btn1.gif"></a><a href="#"><img src="imgs/btn2.gif"></a><a href="#"><img src="imgs/btn3.gif"></a></div>
- <div class="text" id="txt"><a href="#" target="_blank">周杰伦最新专辑:《牛仔很忙》</a>|<a href="#" target="_blank">初恋的回忆-《不能说的秘密》</a>|<a href="#" target="_blank">2008贺岁第一棒-《命运呼叫转移》</a></div>
- </div>
- <script type="text/javascript">
- function G(id){
- return document.getElementById(id);
- }
- var imgHeight=283;
- var st = 0;
- var __n=0;
- var sp=0.3;
- var txtLinks =G('txt').innerHTML.split("|");
- var ele=G('img');
- var timers=new Array();
- function slide(n){
- document.title=n;
- G('txt').innerHTML = txtLinks[n];
- timers[1]=setInterval(doSlide,10);
- var btn=G('btn').getElementsByTagName('a');
- for(var i=0; i<3; i++){
- if(i == n){
- btn[n].className = 'btna';
- continue;
- }
- btn[i].className = '';
- }
- }
- function doSlide(){
- var x=ele.scrollTop;
- if(ele.scrollTop==__n*imgHeight){
- __n++;
- if(timers[1]){clearInterval(timers[1])};
- }else{
- stst=st+sp*((__n*imgHeight)-st);
- ele.scrollTop = Math.round(st);
- }
- }
- var slideInit = function(){
- if(__n == 3) __n = 0;
- slide(__n);
- }
- window.onload=function(){
- timers[0]=setInterval(slideInit, 5000);
- var btn=G('btn').getElementsByTagName('a');
- for(var i=0; i<3; i++){
- btn[i].setAttribute("num",i);
- btn[i].onmouseover=function(){clearInterval(timers[0]);}
- btn[i].onclick=function(){if(timers[1]){clearInterval(timers[1])};__n=this.getAttribute("num");slide(__n);}
- btn[i].onmouseout=function(){timers[0]=setInterval(slideInit, 5000);}
- btn[i].onfocus=function(){this.blur()}
- }
- }
- </script>
- </body>
- </html>
上一篇
下一篇

文章来自:
Tags: