例题三、图片轮播

<body>

<div style="width:1000px; height:250px; margin-top:30px">
  <img src="img/11.jpg" width="1000" height="250" />
  <img src="img/22.png" width="1000" height="250" style="display:none" />
  <img src="img/33.png" width="1000" height="250" style="display:none" />
  <img src="img/44.png" width="1000" height="250" style="display:none" />
</div> </body>
<script type="text/javascript"> window.setInterval("Huan()",2000); //找到图片的最大索引
var n = document.getElementsByTagName("img").length-1;
//存当前图片的索引
var d =0;
//换图
function Huan()
{
  var attr = document.getElementsByTagName("img");//找到所有图片
  d++;//当前索引加1
  if(d>n)//判断索引是否超出范围
  {
    d = 0;
  }
  for(var i=0;i<=n;i++)//换图
  {
    attr[i].style.display = "none";//让所有隐藏
  }
  attr[d].style.display = "block";//让该索引的显示
} </script>

例题四、选项卡效果

<style type="text/css">
*{ margin:0px auto; padding:0px}
#menu{ width:240px; height:30px;}
.list{ width:60px; height:30px; float:left; text-align:center; line-height:30px; vertical-align:middle;}
.list:hover{ cursor: pointer}
.nr{ width:240px; height:200px; text-align:center; line-height:200px; vertical-align:middle}
</style> </head> <body> <div style="width:700px; height:500px; margin-top:30px">
  <div id="menu">
    <div class="list" style="background-color:#0F0" onclick="Show('d1')">娱乐</div>
    <div class="list" style="background-color:#369" onclick="Show('d2')">社会</div>
    <div class="list" style="background-color:#F60" onclick="Show('d3')">体育</div>
    <div class="list" style="background-color:#CC3" onclick="Show('d4')">军事</div>
  </div>
  <div id="d1" class="nr" style="background-color:#3C0">娱乐新闻</div>
  <div id="d2" class="nr" style="background-color:#399; display:none">社会新闻</div> //隐藏
  <div id="d3" class="nr" style="background-color:#F30; display:none">体育新闻</div> //隐藏
  <div id="d4" class="nr" style="background-color:#CF3; display:none">军事新闻</div> //隐藏
</div> </body>
<script type="text/javascript"> function Show(id)//鼠标点击执行
{
  var attr = document.getElementsByClassName("nr");//隐藏所有
  for(var i=0;i<attr.length;i++)
  {
    attr[i].style.display = "none";
  }
  document.getElementById(id).style.display = "block";//显示当前的
} </script>

五、滑动效果

<style type="text/css">
*{ margin:0px auto; padding:0px}
#left{ height:600px; background-color:#63C; float:left}
#right{ height:600px; background-color:#F33; float:left}
#btn{ width:30px; height:30px; background-color:#FFF; position:relative; top:285px; color:#60F; font-weight:bold; text-align:center; line-height:30px; vertical-align:middle; float:left}
#btn:hover{ cursor:pointer}
</style>
</head>
<body>
<div style="width:1000px; height:600px">
  <div id="left" style="width:200px;">
  <div id="btn" onclick="Bian()" style="left:185px;">-></div>
</div>
<div id="right" style="width:800px;"></div>
</body>
<script type="text/javascript"> function Bian()//点击->时执行Bian循环
{
  Dong();//执行Dong循环
} function Dong()//循环dong的作用是改变大小和位置
{
  var d1 = document.getElementById("left");//找到id为left的元素
  var d2 = document.getElementById("right");
  var btn = document.getElementById("btn");
  //左侧DIV变宽
  var yskd1 = d1.style.width;
  var w1 = yskd1.substr(0,yskd1.length-2);
  var w1 = parseInt(w1)+2;   d1.style.width = w1+"px";   //右侧DIV变窄
  var yskd2 = d2.style.width;
  var w2 = yskd2.substr(0,yskd2.length-2);
  var w2 = parseInt(w2)-2;
  d2.style.width = w2+"px";   //将按钮移动
  var ysjl = btn.style.left;
  var w3 = ysjl.substr(0,ysjl.length-2);
  var w3 = parseInt(w3)+2;
  btn.style.left = w3+"px";   if(w2>200)
  {
    //自己调自己
    window.setTimeout("Dong()",1);
  } } </script>

例题六、进度条的制作

<style type="text/css">
*{ margin:0px auto; padding:0px}
#wai{ width:200px; height:10px; border:1px solid #60F;}
#nei{ width:0px; height:10px; background-color:#F33; float:left}
</style>
</head>
<body>
<div style="width:600px; height:300px; margin-top:30px">
  <div id="wai"></div>
  <div id="nei"></div>
<input type="button" value="开始" onclick="Start()" />
</div>
</body>
<script type="text/javascript"> function Start()
{
  Bian();
}
var bfb = 0;
function Bian()
{
  //将百分比变化
  bfb= bfb+1;
  //改变宽度
  document.getElementById("nei").style.width = bfb+"%";
  //判断
  if(bfb<100)
  {
    window.setTimeout("Bian()",50);
  }
}
</script>

JS之document例题讲解2的更多相关文章

  1. JS之document例题讲解1(两张表之间数据转移、日期时间选择、子菜单下拉、用div做下拉菜单、事件总结)

    作业一:两个列表之间数据从一个列表移动到另一个列表 <div style="width:600px; height:500px; margin-top:20px"> & ...

  2. JS function document.onclick(){}报错Syntax error on token "function", delete this token

    JS function document.onclick(){}报错Syntax error on token "function", delete this token func ...

  3. js 节点 document html css 表单节点操作

    js 节点 document html css 表单节点操作 节点操作:访问.属性.创建 (1)节点的访问:firstChild.lastChild.childNodes.parentChild(父子 ...

  4. JS 中document.URL 和 window.location.href 的区别

    实际上,document 和 window 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,window 表示一个窗口对象. 一个窗口下面可以有很多的documen ...

  5. 原生js方法document.getElementsByClassName在ie8及其以下的兼容性问题

    document.getElementsByClassName在ie8及其以下浏览器的兼容性问题,在ie8及其以下浏览器中不能使用,针对这个问题,下面给出详细的解决方法,感兴趣的朋友可以参考下     ...

  6. JS中的DOM对象及JS对document对像的操作

    DOM对象 windows:属性:opener(打开者) 方法:open().close(),setTimeout().setInterval()... location:属性:href 方法:rel ...

  7. JS的document.links函数使用示例

    ? <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title&g ...

  8. JS的document.images函数使用示例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. JS的document.anchors函数使用示例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. IT启示录

    引用电影<夏洛特烦恼>中夏洛的一句话:"一直以来,我根本就不知道自己想要什么".可以说在写这篇博客之前我仍然没有考虑清楚之后的道路,即使早已明确了走游戏开发的道理,却不 ...

  2. Swift-(OC中的enumerateObjectsUsingBlock跟Swift的enumerate区别)

    OC中使用: NSArray * lists = [NSArray array]; [lists enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUI ...

  3. 201621123034 《Java程序设计》第5周学习总结

    作业05-继承.多态.抽象类与接口 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答:关键字:接口.继承.多态 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般 ...

  4. 原生javascript自定义input[type=radio]效果

    2018年6月27日 更新 找到最为简单的仅仅使用css3的方案 <!DOCTYPE html> <html lang="en"> <head> ...

  5. 阻塞 , 非阻塞 , 同步 ,异步 , I/O模型

    •阻塞,非阻塞:进程/线程要访问的数据是否就绪,进程/线程是否需要等待: •同步,异步:访问数据的方式,同步需要主动读写数据,在读写数据的过程中还是会阻塞:异步只需要I/O操作完成的通知,并不主动读写 ...

  6. Matlab快捷键

    1. 在命令窗口(Command Window)中: 1) [上.下键]――切换到之前.之后的命令,可以重复按多次来达到你想要的命令 2) clc――清除命令窗口显示的语句,此命令并不清空当前工作区的 ...

  7. arp获取

    getarp.c /* getarp.c -- This simple program uses an IOCTL socket call to read an entry */ /* from th ...

  8. html5 js canvas中画星星的函数

    function drawStar(cxt, x, y, outerR, innerR, rot) { cxt.beginPath(); ; i < ; i++) { cxt.lineTo(Ma ...

  9. MySQL数据库引擎MyISAM与InnoDB的区别

    1. 存储结构 MyISAM:每个MyISAM在磁盘上存储成三个文件.第一个文件的名字以表的名字开始,扩展名指出文件类型..frm文件存储表定义.数据文件的扩展名为.MYD (MYData).索引文件 ...

  10. hadoop 使用Avro求最大值

    在上例中:hadoop MapReduce辅助排序解析,为了求每年的最大数据使用了mapreduce辅助排序的方法. 本例中介绍利用Avro这个序列化框架的mapreduce功能来实现求取最大值.Av ...