【效果】精辟的抖动效果
作者:青锋幽灵 日期:2008-12-02 10:53
XML/HTML代码
- <img id="win" style='position:relative' src="http://ghost.cmsdream.com/samples/quake/img.jpg"><br /><br />
- <button onclick="quake()">振动</button>
- <script type="text/javascript">
- var a=['top','left'],b=0;
- function quake(u){
- u=setInterval(function(){
- document.getElementById('win').style[a[b%2]]=(b++)%4<2?0:4;
- if(b>15){clearInterval(u);b=0}
- },32);
- }
- </script>
完美js模拟网页对话框效果(可拖曳)
作者:青锋幽灵 日期:2008-10-23 10:51
JavaScript代码
- /**
- Powered By CMSDream Copyright © 2007-2008 All rights reserved.
- 23:25 2008-5-3
- **/
- var msgbox_scripts = document.getElementsByTagName("script");
- msgbox_path = msgbox_path.substring(0, msgbox_path.lastIndexOf('/')+1);
- var CMSMsgBox = function(oWidth, oHeight, oSkin, oTitle){
- this.Id = 'msgbox_'+Math.random().toString().replace('\.', '_');
- /*
- * 位置
- * =================
- * ===== 1 2 3 =====
- * ===== 4 5 6 =====
- * ===== 7 8 9 =====
- * =================
- */
- this.Position = 5;
- this.Skin = oSkin || 'default';
- this.Width = oWidth || 500;
- this.Height = oHeight || 260;
- this.Title = oTitle || 'CMSDream:';
- this.Value = '';
- this.Float = true;
- this.Mask = false;
- this.Drag = true;
- this.Return = false;
- this.BoxDiv = null;
- };
- CMSMsgBox.prototype.show = function(){
- /* 加载样式表 */
- if(!this.$('msgbox_styles')){
- var css = document.createElement('link');
- css.setAttribute('href', msgbox_path + 'msgbox.css');
- css.setAttribute('id', 'msgbox_styles');
- css.setAttribute('rel', 'stylesheet');
- css.setAttribute('type', 'text/css');
- document.getElementsByTagName('head')[0].appendChild(css);
- }
- if(this.$(this.Id))return false;
- this.Return = true;
- this.BoxDiv = this.createDiv(document.body, 'div', 'block', this.Id, 'msgbox_main_div');
- if(this.Mask)this.createMask();
- this.showBox();
- };
- CMSMsgBox.prototype.showBox = function(){
- var self = this;
- var div = new Array();
- div['box'] = this.createDiv(this.BoxDiv, 'div', 'block', this.Id+'bgcolor_div', 'msgbox_box msgbox_box_'+this.Skin);
- if(this.Width)div['box'].style.width = this.Width+'px';
- if(this.Height && this.Skin != 'loading')div['box'].style.height = this.Height+'px';
- div['title'] = this.createDiv(div['box'], 'div', null, null, 'msgbox_title');
- /* =====================================
- * 拖曳效果
- *=====================================**/
- if(this.Drag){
- div['move'] = this.createDiv(this.BoxDiv, 'div', 'none', null, 'msgbox_move_div');
- div['title'].style.cursor = 'move';
- div['title'].onmousedown = function(e){
- var X = document.all ? event.clientX : e.pageX;
- var Y = document.all ? event.clientY : e.pageY;
- var T = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
- var cLeft = div['code'].offsetLeft + div['box'].offsetLeft;
- var cTop = div['code'].offsetTop + div['box'].offsetTop - T;
- if((X > cLeft && X < (cLeft + div['code'].offsetWidth)) && (Y > cTop && Y < (cTop + div['code'].offsetHeight)))
- return;
- this.style.zIndex += 10;
- this.setAttribute('MD', '1');
- this.setAttribute('XCX', parseInt(X - div['box'].offsetLeft).toString());
- this.setAttribute('XCY', parseInt(Y - div['box'].offsetTop).toString());
- div['move'].style.width = parseInt(div['box'].offsetWidth-10) + 'px';
- div['move'].style.height = parseInt(div['box'].offsetHeight - 10) + 'px';
- div['move'].style.left = div['box'].offsetLeft + 'px';
- div['move'].style.top = div['box'].offsetTop + 'px';
- div['move'].style.display = 'block';
- };
- document.onmousemove = function(e){
- if(div['title'].getAttribute('MD')!='1')return;
- var XCX = div['title'].getAttribute('XCX');
- var XCY = div['title'].getAttribute('XCY');
- var X = document.all ? event.clientX : e.pageX;
- var Y = document.all ? event.clientY : e.pageY;
- div['move'].style.left = parseInt(X - XCX) + 'px';
- div['move'].style.top = parseInt(Y - XCY) + 'px';
- };
- document.onmouseup = function(e){
- if(div['title'].getAttribute('MD')!='1')return;
- div['title'].setAttribute('MD', '0');
- div['title'].setAttribute('XCX', '0');
- div['title'].setAttribute('XCY', '0');
- div['box'].style.left = div['move'].offsetLeft + 'px';
- div['box'].style.top = div['move'].offsetTop + 'px';
- if(self.IsObject(div['mask'])){
- div['mask'].style.left = div['move'].offsetLeft + 'px';
- div['mask'].style.top = div['move'].offsetTop + 'px';
- }
- div['move'].style.display = 'none';
- };
- }
- div['span'] = this.createDiv(div['title'], 'span', 'block', this.Id+'_msgTitle');
- div['span'].innerHTML = this.Title;
- /* =====================================
- * 关闭按钮
- *=====================================**/
- div['code'] = this.createDiv(div['title'], 'code', 'block');
- div['code'].setAttribute('title', 'close');
- div['code'].style.position = 'relative';
- div['code'].innerHTML = "close";
- div['code'].onclick = function(){self.close();};
- /* =====================================
- * 文本区域
- *=====================================**/
- div['text'] = this.createDiv(div['box'], 'div', 'block', this.Id+'_msgContent', 'msgbox_content');
- div['value'] = this.createDiv(div['text'], 'div', 'block', this.Id+'_msgValue', 'msgbox_container');
- div['clear'] = this.createDiv(div['text'], 'div', 'block', null, 'msgbox_clear');
- if(this.Height && this.Skin != 'loading'){
- div['value'].style.height = (div['box'].offsetHeight - div['title'].offsetHeight - 16) + 'px';
- div['value'].style.overflowY = 'auto';
- }
- div['value'].innerHTML = this.Value;
- /* =====================================
- * 创建一个iframe档住select
- *=====================================**/
- if(document.all && !this.Mask){
- div['mask'] = this.createDiv(this.BoxDiv, 'iframe', 'block', null, 'msgbox_frame');
- div['mask'].style.width = div['box'].offsetWidth+'px';
- div['mask'].style.height = div['box'].offsetHeight+'px';
- }
- mDiv_Float();
- if(this.Float){
- if(window.addEventListener){
- window.addEventListener('resize', mDiv_Float, false);
- window.addEventListener('scroll', mDiv_Float, false);
- }else{
- window.attachEvent('onresize', mDiv_Float);
- window.attachEvent('onscroll', mDiv_Float);
- }
- }
- /* =====================================
- * 漂浮效果
- *=====================================**/
- function mDiv_Float(){
- var t = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
- var h = document.documentElement.clientHeight ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : document.body.clientHeight;
- var w = document.documentElement.clientWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
- switch(self.Position){
- case 1: {var l = 1;var r = t + 1;break;}
- case 2: {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = t + 1;break;}
- case 3: {var l = parseInt(w-div['box'].offsetWidth-1);var r = t + 1;break;}
- case 4: {var l = 1;var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
- case 5: {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
- case 6: {var l = parseInt(w-div['box'].offsetWidth-1);var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
- case 7: {var l = 1;var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
- case 8: {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
- case 9: {var l = parseInt(w-div['box'].offsetWidth-1);var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
- default: {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
- }
- div['box'].style.left = l+'px';
- div['box'].style.top = r+'px';
- if(document.all && !self.Mask){
- div['mask'].style.left = l+'px';
- div['mask'].style.top = r+'px';
- }
- }
- };
- /* 蒙板 */
- CMSMsgBox.prototype.createMask = function(){
- var self = this;
- var div = new Array(1);
- if(document.all)
- div['mask_ifr'] = this.createDiv(this.BoxDiv, 'iframe', 'block', null, 'msgbox_mask_frame');
- div['mask_div'] = this.createDiv(this.BoxDiv, 'div', 'block', null, 'msgbox_mask_div');
- function window_onresize(){
- var h = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
- var w = document.all ? Math.min(document.documentElement.scrollWidth, document.body.scrollWidth) :
- Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
- div['mask_div'].style.width = w + 'px';
- div['mask_div'].style.height = h + 'px';
- if(document.all){
- div['mask_ifr'].style.width = div['mask_div'].offsetWidth + 'px';
- div['mask_ifr'].style.height = div['mask_div'].offsetHeight + 'px';
- }
- }
- if(window.addEventListener){
- window.addEventListener('scroll', window_onresize, false);
- window.addEventListener('resize', window_onresize, false);
- }else{
- window.attachEvent('onscroll', window_onresize);
- window.attachEvent('onresize', window_onresize);
- }
- if(this.Skin=='loading')div['mask_div'].ondblclick = function(){self.close();};
- window_onresize();
- };
- /* 创建一个元素 */
- CMSMsgBox.prototype.createDiv = function(iParent, element, display, id, clsname){
- var ii = document.createElement(element);
- if(typeof(display)=='string')ii.style.display = display;
- if(typeof(clsname)=='string')ii.className = clsname;
- if(typeof(id)=='string')ii.setAttribute('id', id);
- iParent.appendChild(ii);
- return ii;
- };
- /* 关闭 */
- CMSMsgBox.prototype.close = function(){
- if(this.IsObject(this.BoxDiv) && this.BoxDiv.parentNode){
- this.BoxDiv.parentNode.removeChild(this.BoxDiv);
- }
- };
- CMSMsgBox.prototype.$ = function(o){
- return document.getElementById(o);
- };
- CMSMsgBox.prototype.IsObject = function(o){
- return typeof(o)!='undefined' && o!=null;
- };
- CMSMsgBox.prototype.setBackgroundColor=function(iColor){
- if(!this.$(this.Id+'bgcolor_div'))return;
- this.$(this.Id+'bgcolor_div').style.backgroundColor = iColor;
- };
- CMSMsgBox.prototype.setColor=function(iColor){
- if(!this.$(this.Id+'_msgValue'))return;
- this.$(this.Id+'_msgValue').style.color = iColor;
- };
- CMSMsgBox.prototype.setValue=function(iValue){
- if(!this.$(this.Id+'_msgValue'))return;
- this.$(this.Id+'_msgValue').innerHTML = iValue;
- };
- CMSMsgBox.prototype.setTitle=function(iTitle){
- if(!this.$(this.Id+'_msgTitle'))return;
- this.$(this.Id+'_msgTitle').innerHTML = iTitle;
- };
标签: javascript,拖曳,模拟
图片连续滚动(缓冲,一停一顿效果),可左右翻滚
作者:青锋幽灵 日期:2008-09-12 10:31
样式表代码(scroll.css):
CSS代码
- * {margin:0;padding:0;}
- body {width:370px;}
- a {text-decoration:none;color:#000;}
- a:hover {text-decoration:underline;color:#f00;}
- ul,li {float:left;width:100%;list-style-type:none;}
- h3,h3 a {font-size:12px;font-weight:normal;font-family:"宋体",Verdana;}
- .bc {height:90px;clear:both;overflow:hidden;padding:3px 15px 0 15px;}
- .bc a.scroll {width:12px;height:46px;overflow:hidden;text-indent:-100px;margin-top:5px;background:#333;}
- .bc a.s1 {float:left;}
- .bc a.s2 {float:rightright;}
- #scroll1 {padding:5px 8px 7px 8px;}
- .bc div.scroll {float:left;position:relative;width:318px;left:6px;overflow:hidden;}
- div.scroll ul {width:8000%;}
- div.scroll ul li {width:106px;padding:0 0 2px 0;text-align:center;}
- div.scroll ul li img {clear:both;width:90px;height:60px;border:1px solid #ccc;margin:0 auto;}
- div.scroll ul li h3 {height:20px;line-height:20px;overflow:hidden;}
- div.scroll ul li h3,div.scroll ul li h3 a {color:#c00;font-family:"宋体";}
效果JS代码(scroll.js):
JavaScript代码
- function scroll_initialize(Id){
- var self =this;
- var obj = document.getElementById(Id);
- if(obj.getElementsByTagName('li').length==0)return;
- var links = obj.getElementsByTagName('a');
- var a = links[0];
- var b = links[links.length-1];
- var ul = obj.getElementsByTagName('ul')[0];
- var div = obj.getElementsByTagName('div')[0];
- var li_width = obj.getElementsByTagName('li')[0].offsetWidth;
- var li_count = obj.getElementsByTagName('li').length;
- var ul_width = li_width * li_count;
- this.speed = 2000;
- this.mar = null;
- this.doSlide = function(n,t,d,c){
- var timers=new Array(n);
- var x=div.scrollLeft;
- for(var i=0;i<n;i++)(function(){
- if(timers[i]) clearTimeout(timers[i]);
- var j=i;
- timers[i]=setTimeout(function(){
- if(d==0){
- if(ul_width-div.scrollLeft<=0){
- div.scrollLeft-=ul_width;
- }else{
- div.scrollLeft=x+Math.round((c*li_width)*Math.sin(Math.PI*(j+1)/(2*n)));
- }
- }else{
- if(div.scrollLeft<=0){
- }else{
- div.scrollLeft=x-Math.round((c*li_width)*Math.sin(Math.PI*(j+1)/(2*n)));
- }
- }
- },(i+1)*t);
- })();
- if(ul_width-div.scrollLeft<=0 || (div.scrollLeft % li_width != 0 && div.scrollLeft != 0)){
- div.scrollLeft=0;
- }
- }
- this.istop=function(){
- clearInterval(self.mar);
- };
- this.istart=function(){
- self.mar = setInterval(function(){self.doSlide(20,40,0,1);},self.speed);
- };
- this.initialize = function(){
- ul.innerHTML+=ul.innerHTML;
- ul.style.width = parseInt(ul_width * 2) + 'px';
- a.onclick=function(e){self.doSlide(20,40,0,3);return false;};
- a.onfocus=function(){this.blur();};
- a.onmouseout=function(){self.istart();};
- a.onmouseover=function(){self.istop();};
- b.onclick=function(e){self.doSlide(20,40,1,3);return false;};
- b.onfocus=function(){this.blur();};
- b.onmouseout=function(){self.istart();};
- b.onmouseover=function(){self.istop();};
- div.onmouseout=function(){self.istart();};
- div.onmouseover=function(){self.istop();};
- this.istart();
- };
- this.initialize();
- }
页面HTML代码(scroll.html):
XML/HTML代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>doc1</title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <link href="scroll.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="scroll.js"></script>
- </head>
- <body>
- <div class="bc" id="scroll1">
- <a href="#left" class="scroll s1" title="向左滚动">向左滚动</a>
- <div class="scroll">
- <ul>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h69/img200809111627130.jpg" /></a>
- <h3><a href="#">魔幻《天地OL》</a></h3>
- </li>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h68/img200809091601330.jpg" /></a>
- <h3><a href="#">《名将三国》</a></h3>
- </li>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051655460.jpg" /></a>
- <h3><a href="#">变型金刚OL</a></h3>
- </li>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051653330.jpg" /></a>
- <h3><a href="#">盛大《八门OL》</a></h3>
- </li>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h67/img200809051650450.jpg" /></a>
- <h3><a href="#">回合制《穿越OL》</a></h3>
- </li>
- <li>
- <a href="#"><img src="http://image2.766.com/res/h000/h69/img200809111633050.jpg" /></a>
- <h3><a href="#">卡通网页游戏乐土</a></h3>
- </li>
- </ul>
- </div>
- <a href="#right" class="scroll s2" title="向右滚动">向右滚动</a>
- </div>
- </body>
- </html>
效果预览:

代码下载:点击下载
获取js后所带的参数,如:a.js?a=value1&b=value2
作者:青锋幽灵 日期:2008-09-10 11:23
将以下代码保存为:a.js
JavaScript代码
- function querystring(){
- this.params = new Object();
- this.initialize = function(){
- var param=this.paramstring();
- if(param.length == 0) return;
- if(param.substring(0,1)=='?'){
- param=param.substring(1);
- }
- param = param.replace(/\+/g, ' ');
- var args = param.split('&');
- for (var i=0;i<args.length;i++){
- var value;
- var pair = args[i].split('=');
- var name = unescape(pair[0]);
- if (pair.length == 2)
- value = unescape(pair[1]);
- else
- value = name;
- this.params[name] = value;
- }
- };
- this.get = function(key, defvalue){
- return this.params[key]==null?defvalue:this.params[key];
- };
- this.paramstring = function(){
- var col=document.getElementsByTagName("script");
- var jsrc=col.item(col.length-1).src;
- var i=jsrc.indexOf("?");
- var words=jsrc.substr(i+1,jsrc.length);
- return(words);
- };
- this.initialize();
- }
- var q = new querystring();
- var a = q.get('a','defaultvalue'); //defaultvalue是默认值
- var b = q.get('b','defaultvalue'); //defaultvalue是默认值
调用:
XML/HTML代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <script type="text/javascript" src="a.js?a=baidu&b=google"></script>
- <title>无标题文档</title>
- </head>
- <body>
- <!--
- js运行结果将得到:
- a=baidu
- b=google
- -->
- </body>
- </html>
是不是很有趣呢?呵呵~~
标签: javascript 参数
一天弹出一次的广告JS代码
作者:青锋幽灵 日期:2008-09-10 02:02
有一个页面有两条图片广告,当用户访问这个页面时按十分之一的概率随机点击两个广告中的一个广告,当该用户已经弹出过广告则一天内不再弹出。
主函数:
name:cookie名称
urls:广告地址数组
width:宽度
height:高度
JavaScript代码
- function popad(name,urls,width,height)
- {
- if(!name || !urls) return false;
- width = width ? width : 300;
- height = height ? height : 300;
- var cookieString = new String(document.cookie);
- var cookieName = name+'=';
- var pos = cookieString.indexOf(cookieName);
- if (pos <0){
- if(rand(10)==1) {
- url = urls[rand(urls.length)-1];
- window.open(url,'hello','location=yes,resizable=yes,width='+width+',height='+height);
- var now = new Date();
- expiredate = new Date(now.getYear(),now.getMonth(),now.getDate(),23,59,59);
- document.cookie = name+'=opened;expires='+ expiredate.toGMTString();
- }
- }
- }
随机函数:
返回的值为1~number的值。
JavaScript代码
- function rand(number) {
- return Math.floor(Math.random() * number + 1);
- }
调用:
JavaScript代码
- adurls = new Array('http://www.163.com','http://www.cnfol.com');
- popad('popad', adurls, 800, 600);
Javacript+xml+DOM 浏览器兼容性问题
作者:青锋幽灵 日期:2008-09-09 15:13
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",
一 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",
一个简单的Ajax类
作者:青锋幽灵 日期:2008-09-08 11:44
JavaScript代码
- /**
- Powered By CMSDream Copyright © 2007-2008 All rights reserved.
- 14:21 2008-5-10
- **/
- function CMSDreamAjaxLib(){
- /**//**
- 成员变量
- */
- this.XMLHttpReq = null; //XML对象
- this.method = "post"; //执行的方法(post/get)
- this.url = ""; //异步调用的页面地址
- this.responseText = ""; //异步返回的响应字符串
- this.responseXML = ""; //异步返回的响应XML
- this.failed = false; //创建对象错误标志
- /**//**
- 事件区
- */
- this.onLoading = function() {}; //正在发送请求
- this.onLoaded = function() {}; //已经接收到全部响应内容
- this.onInteractive = function() {}; //正在解析响应内容
- this.onCompletion = function() {}; //响应内容解析完成
- this.onError = function
