预览模式: 普通 | 列表

图片连续滚动(缓冲,一停一顿效果),可左右翻滚

样式表代码(scroll.css):

CSS代码
  1. * {margin:0;padding:0;}   
  2. body {width:370px;}   
  3. a {text-decoration:none;color:#000;}   
  4. a:hover {text-decoration:underline;color:#f00;}   
  5. ul,li {float:left;width:100%;list-style-type:none;}   
  6. h3,h3 a {font-size:12px;font-weight:normal;font-family:"宋体",Verdana;}   
  7.   
  8. .bc {height:90px;clear:both;overflow:hidden;padding:3px 15px 0 15px;}   
  9. .bc a.scroll {width:12px;height:46px;overflow:hidden;text-indent:-100px;margin-top:5px;background:#333;}   
  10. .bc a.s1 {float:left;}   
  11. .bc a.s2 {float:rightright;}   
  12.   
  13. #scroll1 {padding:5px 8px 7px 8px;}   
  14. .bc div.scroll {float:left;position:relative;width:318px;left:6px;overflow:hidden;}   
  15.        
  16. div.scroll ul {width:8000%;}   
  17. div.scroll ul li {width:106px;padding:0 0 2px 0;text-align:center;}   
  18. div.scroll ul li img {clear:both;width:90px;height:60px;border:1px solid #ccc;margin:0 auto;}   
  19. div.scroll ul li h3 {height:20px;line-height:20px;overflow:hidden;}   
  20. div.scroll ul li h3,div.scroll ul li h3 a {color:#c00;font-family:"宋体";}  

效果JS代码(scroll.js):

JavaScript代码
  1. function scroll_initialize(Id){   
  2.     var self    =this;   
  3.     var obj     = document.getElementById(Id);   
  4.     if(obj.getElementsByTagName('li').length==0)return;   
  5.     var links   = obj.getElementsByTagName('a');   
  6.     var a       = links[0];   
  7.     var b       = links[links.length-1];       
  8.     var ul      = obj.getElementsByTagName('ul')[0];   
  9.     var div     = obj.getElementsByTagName('div')[0];   
  10.         
  11.     var li_width    = obj.getElementsByTagName('li')[0].offsetWidth;   
  12.     var li_count    = obj.getElementsByTagName('li').length;   
  13.     var ul_width    = li_width * li_count;   
  14.        
  15.     this.speed      = 2000;   
  16.     this.mar        = null;   
  17.   
  18.     this.doSlide = function(n,t,d,c){   
  19.         var timers=new Array(n);   
  20.         var x=div.scrollLeft;   
  21.         for(var i=0;i<n;i++)(function(){   
  22.             if(timers[i]) clearTimeout(timers[i]);   
  23.             var j=i;   
  24.             timers[i]=setTimeout(function(){   
  25.                 if(d==0){   
  26.                     if(ul_width-div.scrollLeft<=0){   
  27.                         div.scrollLeft-=ul_width;   
  28.                     }else{             
  29.                         div.scrollLeft=x+Math.round((c*li_width)*Math.sin(Math.PI*(j+1)/(2*n)));   
  30.                     }   
  31.                 }else{   
  32.                     if(div.scrollLeft<=0){   
  33.                     }else{             
  34.                         div.scrollLeft=x-Math.round((c*li_width)*Math.sin(Math.PI*(j+1)/(2*n)));   
  35.                     }   
  36.                 }   
  37.             },(i+1)*t);   
  38.         })();   
  39.   
  40.         if(ul_width-div.scrollLeft<=0 || (div.scrollLeft % li_width != 0 && div.scrollLeft != 0)){   
  41.             div.scrollLeft=0;   
  42.         }   
  43.     }      
  44.     this.istop=function(){   
  45.         clearInterval(self.mar);   
  46.     };   
  47.     this.istart=function(){   
  48.         self.mar = setInterval(function(){self.doSlide(20,40,0,1);},self.speed);   
  49.     };   
  50.        
  51.     this.initialize = function(){          
  52.         ul.innerHTML+=ul.innerHTML;   
  53.         ul.style.width = parseInt(ul_width * 2) + 'px';   
  54.         a.onclick=function(e){self.doSlide(20,40,0,3);return false;};   
  55.         a.onfocus=function(){this.blur();};   
  56.         a.onmouseout=function(){self.istart();};   
  57.         a.onmouseover=function(){self.istop();};   
  58.         b.onclick=function(e){self.doSlide(20,40,1,3);return false;};   
  59.         b.onfocus=function(){this.blur();};   
  60.         b.onmouseout=function(){self.istart();};   
  61.         b.onmouseover=function(){self.istop();};   
  62.         div.onmouseout=function(){self.istart();};   
  63.         div.onmouseover=function(){self.istop();};   
  64.         this.istart();   
  65.     };   
  66.        
  67.     this.initialize();   
  68. }  

页面HTML代码(scroll.html):

XML/HTML代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <title>doc1</title>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  6. <link href="scroll.css" rel="stylesheet" type="text/css" />  
  7. <script type="text/javascript" src="scroll.js"></script>  
  8. </head>  
  9.   
  10. <body>  
  11. <div class="bc" id="scroll1">  
  12.     <a href="#left" class="scroll s1" title="向左滚动">向左滚动</a>  
  13.     <div class="scroll">  
  14.         <ul>  
  15.             <li>  
  16.                 <a href="#"><img src="http://image2.766.com/res/h000/h69/img200809111627130.jpg" /></a>  
  17.                 <h3><a href="#">魔幻《天地OL》</a></h3>  
  18.             </li>  
  19.             <li>  
  20.                 <a href="#"><img src="http://image2.766.com/res/h000/h68/img200809091601330.jpg" /></a>  
  21.                 <h3><a href="#">《名将三国》</a></h3>  
  22.             </li>  
  23.             <li>  
  24.                 <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051655460.jpg" /></a>  
  25.                 <h3><a href="#">变型金刚OL</a></h3>  
  26.             </li>  
  27.             <li>  
  28.                 <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051653330.jpg" /></a>  
  29.                 <h3><a href="#">盛大《八门OL》</a></h3>  
  30.             </li>  
  31.             <li>  
  32.                 <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051650450.jpg" /></a>  
  33.                 <h3><a href="#">回合制《穿越OL》</a></h3>  
  34.             </li>  
  35.             <li>  
  36.                 <a href="#"><img src="http://image2.766.com/res/h000/h69/img200809111633050.jpg" /></a>  
  37.                 <h3><a href="#">卡通网页游戏乐土</a></h3>  
  38.             </li>  
  39.         </ul>  
  40.     </div>  
  41.     <a href="#right" class="scroll s2" title="向右滚动">向右滚动</a>  
  42. </div>  
  43. </body>  
  44. </html>  

 

 效果预览:

效果预览

代码下载:点击下载

获取js后所带的参数,如:a.js?a=value1&b=value2

将以下代码保存为:a.js 

JavaScript代码
  1. function querystring(){      
  2.     this.params = new Object();      
  3.     this.initialize = function(){      
  4.         var param=this.paramstring();      
  5.         if(param.length == 0) return;      
  6.         if(param.substring(0,1)=='?'){      
  7.             param=param.substring(1);      
  8.         }      
  9.         param = param.replace(/\+/g, ' ');      
  10.         var args = param.split('&');          
  11.         for (var i=0;i<args.length;i++){      
  12.             var value;      
  13.             var pair = args[i].split('=');      
  14.             var name = unescape(pair[0]);      
  15.             if (pair.length == 2)      
  16.                 value = unescape(pair[1]);      
  17.             else     
  18.                 value = name;             
  19.             this.params[name] = value;      
  20.         }      
  21.     };      
  22.     this.get = function(key, defvalue){      
  23.         return this.params[key]==null?defvalue:this.params[key];      
  24.     };      
  25.     this.paramstring = function(){       
  26.         var col=document.getElementsByTagName("script");       
  27.         var jsrc=col.item(col.length-1).src;       
  28.         var i=jsrc.indexOf("?");       
  29.         var words=jsrc.substr(i+1,jsrc.length);       
  30.         return(words);       
  31.     };      
  32.     this.initialize();      
  33. }      
  34.      
  35. var q = new querystring();      
  36. var a = q.get('a','defaultvalue'); //defaultvalue是默认值      
  37. var b = q.get('b','defaultvalue'); //defaultvalue是默认值   

调用:    

XML/HTML代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <script type="text/javascript" src="a.js?a=baidu&b=google"></script>  
  6. <title>无标题文档</title>  
  7. </head>  
  8.   
  9. <body>  
  10. <!--   
  11.   js运行结果将得到:   
  12.   a=baidu  
  13.   b=google  
  14. -->  
  15. </body>  
  16. </html>  

 

是不是很有趣呢?呵呵~~

隐藏文件名后缀的URL Rewrite

我看网上有很多此类功能,当然asp.net自身很容易实现,但是其它的要实现会出现一点小问题,本人写了一个,经过测试没有任何问题,应该也支持apache。

代码如下:

RewriteRule ^(.*)/([\w\-]+)\?(.*)$ $1/$2\.asp\?$3
RewriteRule ^(.*)/([\w\-]+)$ $1/$2.asp

标签: URLRewrite

一天弹出一次的广告JS代码

有一个页面有两条图片广告,当用户访问这个页面时按十分之一的概率随机点击两个广告中的一个广告,当该用户已经弹出过广告则一天内不再弹出。

主函数:

name:cookie名称
urls:广告地址数组
width:宽度
height:高度 

JavaScript代码
  1. function popad(name,urls,width,height)        
  2. {       
  3.     if(!name || !urls) return false;       
  4.     width = width ? width : 300;       
  5.     height = height ? height : 300;       
  6.     var cookieString = new String(document.cookie);       
  7.     var cookieName = name+'=';       
  8.     var pos = cookieString.indexOf(cookieName);       
  9.     if (pos <0){       
  10.         if(rand(10)==1) {       
  11.             url = urls[rand(urls.length)-1];       
  12.             window.open(url,'hello','location=yes,resizable=yes,width='+width+',height='+height);        
  13.             var now = new Date();       
  14.             expiredate = new Date(now.getYear(),now.getMonth(),now.getDate(),23,59,59);       
  15.             document.cookie = name+'=opened;expires='+ expiredate.toGMTString();       
  16.         }       
  17.     }        
  18. }   

 随机函数:

返回的值为1~number的值。 

JavaScript代码
  1. function rand(number) {       
  2.     return Math.floor(Math.random() * number + 1);       
  3. }  

 调用: 

JavaScript代码
  1. adurls = new Array('http://www.163.com','http://www.cnfol.com');       
  2. popad('popad', adurls, 800, 600);   

SQLServer 通用分页存储过程(使用游标)

SQL代码
  1. ----------------------------------------------------------------------   
  2. -- 通用分页存储过程   
  3. ----------------------------------------------------------------------   
  4. CREATE PROCEDURE [dbo].[cmsdream_SP_MultiPage](   
  5.     @sql varchar(8000)='',   
  6.     @PageSize int=1,   
  7.     @CurrentPage int=1,   
  8.     @RecordCount int=0 output,   
  9.     @PageCount int=1 output  
  10. )AS  
  11. if @PageSize < 1 set @PageSize = 1   
  12. if @CurrentPage < 1 set @CurrentPage = 1   
  13. begin  
  14.     set nocount on  
  15.   
  16.     declare @p1 int,   
  17.     @rowcount int  
  18.     exec sp_cursoropen @p1 output,@sql,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output  
  19.     set @PageCount = ceiling(1.0 * @rowcount / @PageSize)      
  20.     set @CurrentPage = (@CurrentPage - 1) * @PageSize + 1   
  21.     set @RecordCount = @rowcount   
  22.     exec sp_cursorfetch @p1, 16, @CurrentPage, @PageSize   
  23.     set nocount off  
  24. end  
  25.   
  26.   
  27. GO  

Javacript+xml+DOM 浏览器兼容性问题

javacript中对xml dom的支持,与其他任何特性一样面临着浏览器兼容问题。

一 IE中的XML DOM
1.微软通过ActiveX的MSXML库提供了支持,通过:
var oXmlDom = new ActiveXObject("MSXML2.DOMDocument.5.0")得到一个XML DOM对象,这是在IE6中的,如果你的IE是更老版本的,可以使用下面的函数得到,如果你没有安装MSXML,将不能得到:

[code]
function createXMLDOM() {

var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",

[阅读全文]

标签: javascript xml dom

一个简单的Ajax类

JavaScript代码
  1. /**  
  2.     Powered By CMSDream Copyright © 2007-2008 All rights reserved.  
  3.     14:21 2008-5-10  
  4. **/  
  5. function CMSDreamAjaxLib(){   
  6.     /**//**  
  7.     成员变量  
  8.     */  
  9.     this.XMLHttpReq = null;         //XML对象   
  10.     this.method = "post";           //执行的方法(post/get)   
  11.     this.url = "";              //异步调用的页面地址   
  12.     this.responseText = "";         //异步返回的响应字符串   
  13.     this.responseXML = "";          //异步返回的响应XML   
  14.     this.failed = false;            //创建对象错误标志   
  15.        
  16.     /**//**  
  17.     事件区  
  18.     */  
  19.     this.onLoading = function() {};     //正在发送请求   
  20.     this.onLoaded = function() {};      //已经接收到全部响应内容   
  21.     this.onInteractive = function() {}; //正在解析响应内容   
  22.     this.onCompletion = function() {};  //响应内容解析完成   
  23.     this.onError = function() {};       //异步错误处理事件   
  24.     this.onFail = function() {};        //创建对象失败处理世界   
  25.        
  26.     /**//**  
  27.     重置所有事件函数  
  28.     */  
  29.     this.resetFunctions = function() {   
  30.         this.onLoading = function() {};   
  31.         this.onLoaded = function() {};   
  32.         this.onInteractive = function() {};   
  33.         this.onCompletion = function() {};   
  34.         this.onError = function() {};   
  35.         this.onFail = function() {};   
  36.     };   
  37.     
  38.     /**//**  
  39.     初始化函数(构造时自动初始化)  
  40.     */  
  41.     this.init = function(){   
  42.         if(window.XMLHttpRequest){   
  43.             this.XMLHttpReq = new XMLHttpRequest();   
  44.         }else if (window.ActiveXObject){   
  45.             try{this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP");}   
  46.             catch(e){   
  47.                 try{this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP");}   
  48.                 catch(e){   
  49.                     try{this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");}   
  50.                     catch(e){   
  51.                         try{this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");}   
  52.                         catch(oc){this.failed=true;}   
  53.                     }   
  54.                 }   
  55.             }   
  56.         }   
  57.     };   
  58.        
  59.     /**//**  
  60.     发送请求函数  
  61.     @param data 发送的数据  
  62.     @example send("id=1");  
  63.     */  
  64.     this.send=function(data){   
  65.         var self=this;   
  66.         if(this.method=="post") {   
  67.             this.XMLHttpReq.open(self.method,self.url,true);   
  68.         }else{   
  69.             this.XMLHttpReq.open(self.method,self.url+"?"+encodeURI(data),true);   
  70.         }   
  71.         //添加消息响应头   
  72.         this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");   
  73.            
  74.         //异步回调函数   
  75.         this.XMLHttpReq.onreadystatechange = function(){   
  76.             //对象未创建   
  77.             if (self.failed) {   
  78.                 self.onFail();   
  79.                 return;   
  80.             }   
  81.                
  82.             //消息响应标志   
  83.             switch (self.XMLHttpReq.readyState) {   
  84.                 case 1:{   
  85.                     self.onLoading();   
  86.                     break;   
  87.                 }   
  88.                 case 2:{   
  89.                     self.onLoaded();   
  90.                     break;   
  91.                 }   
  92.                 case 3:{   
  93.                     self.onInteractive();   
  94.                     break;   
  95.                 }   
  96.                 case 4:{   
  97.                     self.responseText = self.XMLHttpReq.responseText;   
  98.                     self.responseXML = self.XMLHttpReq.responseXML;   
  99.                     self.onCompletion();   
  100.                     break;   
  101.                 }   
  102.             }   
  103.         };   
  104.            
  105.            
  106.         if(this.method=="post"){   
  107.             this.XMLHttpReq.send(data); //发送请求   
  108.         }else{   
  109.             this.XMLHttpReq.send();     //发送请求   
  110.         }   
  111.     };   
  112.        
  113.     this.abort=function(){   
  114.         this.XMLHttpReq.abort();   
  115.     }   
  116.        
  117.     this.close=function(){   
  118.         this.XMLHttpReq=null;   
  119.     }   
  120.     this.init();   
  121. }  
标签: ajax javascript

动态加载样式元素的函数(兼容IE,FireFox,Opera)

如题,目前只对IE,FireFox,Opera这三种浏览器的兼容性进行过测试,其它浏览器还未测试。

有兴趣的朋友可以研究一下,应该也没问题的。

JavaScript代码
  1. function AttachStyle(styDom, styCss, styId){   
  2.     var istyle = styDom.createElement('style');   
  3.     istyle.setAttribute("type""text/css");   
  4.     if(styId!=null){if(!document.getElementById(styId)){istyle.setAttribute("id", styId);}}   
  5.     if (istyle.styleSheet){   
  6.         istyle.styleSheet.cssText=styCss;   
  7.     }else{   
  8.         istyle.appendChild(styDom.createTextNode(styCss));   
  9.     }   
  10.     styDom.getElementsByTagName("head")[0].appendChild(istyle);   
  11. }  

应用代码:

JavaScript代码
  1. if(!document.getElementById('attach-css-1')){      
  2.     var iCss='';      
  3.     iCss+='.test-style1 {font-size:18px;color:#f60;}';      
  4.     iCss+='.test-style2 {font-size:16px;color:#f60;}';      
  5.     iCss+='.test-style3 {font-size:14px;color:#f60;}';      
  6.     iCss+='.test-style4 {font-size:12px;color:#f60;}';      
  7.     AttachStyle(document,iCss,'attach-css-1');      
  8. }      
  9.      
  10. /**    
  11. 大家可以测试一下 test-style1,test-style2,test-style3 这三个样式变化了吗?    
  12. **/