div固定在窗口的某个地方

<!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=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
  $(function(){
        $("#div_float_right").bind("click",function(){
                if($("#div_float_left").css("display")=="block"){
                 $("#div_float_left").css("display","none"); 
                }else if($("#div_float_left").css("display","none")){
                 $("#div_float_left").css("display","block"); 
                 }
                
                
                });
     
     
      $("#div_float").css("top",0);
      $("#div_float").css("left",$(window).width()-200);  //右上边
     
       $("#div_float").css("left",0);  //左上边
      
       //左下边
        $("#div_float").css("top",$(window).height()-420);  //420等层自身的高度
        
         $("#div_float").css("left",$(window).width()-200);  //右下边 //200等层自身的宽度         $("#div_float").css("top",$(window).height()-402);  

       $(window).bind("scroll",function(){
              var p=$(this);
              var d=$(document);
             // $("#div_float").css("top",p.scrollTop()+110);
              // $("#div_float").css("left",p.scrollLeft()+10);
              // alert(d.scrollTop());
              });
       });
</script>
</head>

<body>

<div id="div_float" style="width:200px; height:400px; border:1px solid #ff0000; line-height:400px; vertical-align:middle; position:fixed; left:px; top:0px; ">
  <div id="div_float_left" style="width:150px; height:300px; border:1px solid #cc66e8; float:left; margin: auto auto;">
       
        </div>
        <div id="div_float_right" style="width:30px; border:1px solid #99bbe8; height:300px; float:left; cursor:pointer"></div>
</div>
<div style="width:1500px; height:1500px; border:1px solid #ccee68"></div>
</body>
</html>
//也就是用窗体的高度或宽度-层自身的高度或宽度附值给层的left,top,再把层的position:fixed就可以了

必须有这句话:

<!DOCTYPE html > 或者<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

才能固定位置;如果还想要100%有用,就用前面那句,既能百分百又能固定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值