关于window对象和js效果案例

   
 
window 对象的常见的方法

  open() 方法    作用是打开一个新的窗口
 
  open("新的地址URL","弹出新的窗口的名字","窗口的特征描述")
 
       注意:窗口的特征描述 是一个字符串,每一个特征用","隔开
 
  window 还有一些子对象
 
        document     ==>  window.document
  location     ==>  window.location
  
  比如:location.href="要跳转的地址";
  history 历史
     history.back()    后退
     history.go()
    
             go(数字) 数字代表要前进的步数
          -1   表示后退,和history.back()作用一样
 
  注意
  setTimeout("要执行的函数名","延迟的时间")   延迟一段时间执行一次
  setInterval("要执行的函数名","间隔的时间")  每隔一段时间执行一次
 
  setTimeout我们经常放到函数里面 ,达到每延迟一段时间执行一次
  例如:
  function aaa(){
 
     setTimeout("aaa()",1000);
  }
 
  --------------------------------------------------
 
  实现一下仿163首页的广告收缩效果
 
  思路:
  1、得有两个Div ,分为上下两部分,上面div的id=top,下面正文部分 div 的id=content。
 
  2、设置div的样式,并且我们让top的高度不断增加
 
  3、当top的高度增加到一定的时候,停止增加,延迟3秒
 
  4、把top部分进行收缩,当hight=0 停止收缩

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>仿163首页的广告收缩效果</title>
<style type="text/css">

#top{
 position:relative;
   }
#content{
 position:absolute;
 }  
  

</style>
</head>

<body style="margin:0px 0px;" οnlοad="moveDown()">
 <div id="top" style="width:100%;height:100px;
 background-color:#F96;">网页的广告部分</div>
   <div id="content" style="width:100%;height:500px;background-color:#FF3;">这是网页正文部分</div>
 
</body>
</html>

<script type="text/javascript">
 
  //定义要移动的距离
  var h=0;
  var maxheight=300;
  var st;
  var top=document.getElementById("top");
    //初始时设置top为隐藏状态
  top.style.display="none";
 //定义让广告部分下拉
  function moveDown(){
 //累加
  h+=2;
    //设置层高度等于我们累加的值
  top.style.height=h;
  //设置层显示
  top.style.display="block";
  //判断是否到最大
  if(h<=maxheight){
   st=setTimeout("moveDown()",50);  
  }else{
   clearTimeout(st); 
   //延迟3秒,开始收缩 
   setTimeout("moveUp()",3000); 
   }
   
  }
 
  //定义让广告部分收缩
   function moveUp(){
   //alert(h); 
   //设置
    h-=2;
    //设置层高度等于我们累加的值
  top.style.height=h;
  //设置层显示
  top.style.display="block";
 
  if(h<=0){
  
   top.style.display="none";
         //清空定时器
   clearTimeout(st);
  setTimeout("moveDown()",3000);
  }else{
     //如果h>0,则继续收缩
      st=setTimeout("moveUp()",50);
   }
 
 
   }

</script>
  ------------------------------------------------------
 
  实现js的进度条
 
  1、设置进度显示的样式
 
  2、计算百分比
  
  3、显示到固定的位置

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js进度条</title>
<script type="text/jscript">
 //要显示的数字
 var c=0;
 //输出显示的内容
 var bar="";
 //要显示的格式
 var style1="|";
 
 function loadBar(){
 
   //拼接显示的字符串内容
  bar=bar+style1;
 //百分比累加
  c++;
  document.getElementById("loadbar").innerHTML=bar+" "+c+"%";
  if(c<100){
  setTimeout("loadBar()",100);
  }else{
  // location="js-shousuo-163.html";
  
   }
 }

</script>
</head>

<body οnlοad="loadBar()">
 <div id="loadbar" style="border:dashed 1px #F00; width:350px;height:20px; margin:auto;">

 </div>


</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值