javascript通用浮动代码

javascript通用浮动代码,可随意定位,修复了一些错误和兼容问题

document.writeln("<style>");
document.writeln(".fixed{  ");
document.writeln(" position: fixed;  ");
document.writeln(" _position: absolute;  ");
document.writeln(" _top: expression(eval(document.documentElement.scrollTop));}  ");
document.writeln("html{  ");
document.writeln(" _text-overflow:ellipsis;  ");
document.writeln("} ");
document.writeln("</style> ");

/*sol修改版本 http://iday.me 2012/01/31 */
/*任意位置浮动固定层*/
/*没剑(http://regedit.cnblogs.com) 2009-03-04*/
/*说明:可以让指定的层浮动到网页上的任何位置,当滚动条滚动时它会保持在当前位置不变,不会产生闪动*/
/*调用:
1 无参数调用:默认浮动在右下角
$("#id").floatdiv();

2 内置固定位置浮动
//右下角
$("#id").floatdiv("rightbottom");
//左下角
$("#id").floatdiv("leftbottom");
//右下角
$("#id").floatdiv("rightbottom");
//左上角
$("#id").floatdiv("lefttop");
//右上角
$("#id").floatdiv("righttop");
//居中
$("#id").floatdiv("middle");

另外新添加了四个新的固定位置方法

middletop(居中置顶)、middlebottom(居中置低)、leftmiddle、rightmiddle

3 自定义位置浮动
$("#id").floatdiv({left:"10px",top:"10px"});
以上参数,设置浮动层在left 10个像素,top 10个像素的位置
*/
jQuery.fn.floatdiv=function(location){
		//判断浏览器版本
	var isIE6=false;
	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
	if(Sys.ie && Sys.ie=="6.0"){
		isIE6=true;
	}
	var windowWidth,windowHeight;//窗口的高和宽
	//取得窗口的高和宽
if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	} else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}

	return this.each(function(){
		var loc;//层的绝对定位位置
		var wrap=$("<div></div>");
		var top=-1;
		if(location==undefined || location.constructor == String){
			switch(location){
				case("rightbottom")://右下角
					loc={right:"0px",bottom:"0px"};
					break;
				case("leftbottom")://左下角
					loc={left:"0px",bottom:"0px"};
					break;
				case("lefttop")://左上角
					loc={left:"0px",top:"0px"};
					top=0;
					break;
				case("righttop")://右上角
					loc={right:"0px",top:"0px"};
					top=0;
					break;
				case("middletop")://居中置顶
					loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};
					top=0;
					break;
				case("middlebottom")://居中置低

					loc={width:"100%",bottom:"0px"};
					break;
				case("middlemiddle")://居中居中
					loc={left:windowWidth/2-$(this).width()/2+"px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("leftmiddle")://左边居中
					loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("rightmiddle")://右边居中
					loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("middle")://居中
					var l=0;//居左
					var t=0;//居上
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					top=t;
					loc={left:l+"px",top:t+"px"};
					break;
				default://默认为右下角
					location="rightbottom";
					loc={right:"0px",bottom:"0px"};
					break;
			}
		}else{
			loc=location;
			//alert(loc.bottom);
			var str=loc.top;
			//09-11-5修改:加上top为空值时的判断
			if (typeof(str)!= 'undefined'){
				str=str.replace("px","");
				top=str;
			}
		}
		/*fied ie6 css hack*/
		if(isIE6){
			if (top>=0)
			{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
			}else{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
			}
		}
		$("body").append(wrap);

		wrap.css(loc).css({position:"fixed"});
	  wrap.css("z-index","999999"); // 使浮动在最前面 sol@iday.me

		if (isIE6)
		{

			wrap.css("position","absolute");
			//没有加这个的话,ie6使用表达式时就会发现跳动现象
			//至于为什么要加这个,还有为什么要加nothing.txt这个,偶也不知道,希望知道的同学可以告诉我
			//$("body").css("background-attachment","fixed").css("background-image","url(/images5/bodybg.gif)");
		}
		//将要固定的层添加到固定层里

		$(this).appendTo(wrap);
	});
};

javascript获取Get参数并跳转代码

<html>
<body>
<script language = "javascript" type="text/javascript">
function $G(){
var Url=top.window.location.href;
var u,g,StrBack='';
if(arguments[arguments.length-1]=="#")
   u=Url.split("#");
else
   u=Url.split("?");
if (u.length==1) g='';
else g=u[1];

if(g!=''){
   gg=g.split("&");
   var MaxI=gg.length;
   str = arguments[0]+"=";
   for(i=0;i<maxi ;i++){
      if(gg[i].indexOf(str)==0) {
        StrBack=gg[i].replace(str,"");
        break;
      }
   }
}
return StrBack;
}
var who=$G("p");
var swturl="http://www.xxx.net/php?id=xxx&p=";
var furl=swturl+who;
var timerID=setTimeout("window.location=furl", 0);
</script>
</maxi></script></body>
</html><html>
</html>

javascript关闭漂浮窗口代码

function close_rswt()
{
  var pf=document.getElementById('rswt');
      pf.style.display="none";

	}

document.writeln("<div id=\"rswt\" >");
document.writeln("<div id=\"dibu-rswt\" ><a onclick=\"close_rswt();return false;\"  href=\"javascript:void(0)\"><font color=red  >关闭</font></a></div>");
document.writeln("<a href=\"xxx\" target=\"_blank\"><img src=\"/images/rswt.gif\" /></a>");
document.writeln("</div>");

Dedecms调用指定栏目的文章标题和内容

{dede:php}
$dsql = new DedeSql(false);
$typeid="82";

$sql="select a.id,a.title,t.typedir,c.body from #@__archives a,#@__arctype t ,#@__addonarticle c where a.typeid=t.id and a.id=c.aid and a.typeid=$typeid order by a.id desc limit 0,3";
$dsql->SetQuery($sql);
$dsql->Execute();
while($arc=$dsql->GetArray()){
        $str.=' <li class="w"><a href="'.substr($arc['typedir'],9).'/'.$arc['id'].'.html" target="_blank">'.cn_substr($arc['title'],40).'...</a></li><li class="d">'.cn_substr(strip_tags($arc['body']),30,6).'..</li>';}
echo $str;

{/dede:php}