www.2527.com_澳门新葡8455手机版_新京葡娱乐场网址_
做最好的网站

JS完成点击循环切换突显内容的主意,JS完成点击

2019-07-05 03:16 来源:未知

正文实例陈诉了JS达成的幻灯片切换显示效果。分享给我们供大家参谋,具体如下:

正文实例汇报了JS达成点击循环切换彰显内容的措施。分享给大家供我们仿效,具体如下:

本文实例陈诉了JS落成点击链接切换展现遮掩内容的点子。分享给大家供我们参谋,具体如下:

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=utf-8" />
<title>纯JS幻灯版</title>
<style type="text/css">
*{ margin:0; padding:0;}
#banner {width:1000px;text-align:left; background:#fff; margin:0 auto;}
#banner img{ display:block; float:left;}
.mainbox{ overflow:hidden; position:relative;}
.flashbox{ overflow:hidden; position:relative;}
.imagebox{ text-align:right;position:relative;z-index:999;}
.bitdiv{display:inline-block;width:18px;height:18px;margin:0 10px 10px 0px;cursor:pointer;float:right;}
.defimg{ background:url(styles/images/ppt_icon2.png);}
.curimg{background:url(styles/images/ppt_icon1.png);}
</style>
<script type="text/javascript" src="styles/js/ppt_ban.js"></script>
</head>
<body>
<div id="banner">
  <script>
   var box =new PPTBox();
   box.width = 1000; //宽度
   box.height = 226;//高度
   box.autoplayer = 3;//自动播放间隔时间
   //box.add({"url":"图片地址","title":"悬浮标题","href":"链接地址"})
   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});
   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});
   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});
   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});
   box.show();
  </script>
</div>
</body>
</html>

Web前端 1

Web前端 2

js:

切切实实代码如下:

现实代码如下:

function PPTBox()
{
  this.uid = PPTBoxHelper.getId();
  PPTBoxHelper.instance[this.uid] = this;
  this._$ = function(id){return document.getElementById(id);};
  this.width = 400;//宽度
  this.height = 300;//高度
  this.picWidth = 15;//小图宽度
  this.picHeight = 12;//小图高度
  this.autoplayer = 4;//自动播放间隔(秒)
  this.target = "_blank";
  this._box = [];
  this._curIndex = 0;
}
PPTBox.prototype =
{
  _createMainBox : function (){
    var flashBoxWidth = this.width * this._box.length;
    var html="<div id='" this.uid "_mainbox' class='mainbox' style='width:" (this.width) "px;height:" (this.height) "px;'>";
    html  = "<div id='" this.uid "_flashbox' class='flashbox' style='width:" flashBoxWidth "px;height:" (this.height) "px;'></div>";
    html  = "<div id='" this.uid "_imagebox' class='imagebox' style='width:" this.width "px;height:" (this.picHeight) "px;top:-" (this.picHeight 20) "px;'></div>";
    html  = "</div>";
    document.write(html);
  },
  _init : function (){
    var picstyle= "";
    var eventstr = "PPTBoxHelper.instance['" this.uid "']";
    var imageHTML="";
    var flashbox = "";
    for(var i=0;i<this._box.length;i  ){
      var parame = this._box[i];
      flashbox  = this.flashHTML(parame.url,this.width,this.height,i);
      imageHTML ="<div class='bitdiv " ((i==0)?"curimg":"defimg") "' title =" parame.title " src='bit01.gif' " picstyle " onclick = "" eventstr ".clickPic(" i ")" onmouseover="" eventstr ".mouseoverPic(" i ")"></div>"   imageHTML;
    }
    this._$(this.uid "_flashbox").innerHTML = flashbox;
    this._$(this.uid "_imagebox").innerHTML = imageHTML;
  },
  _play : function(){
    clearInterval(this._autoplay);
    var idx = this._curIndex 1;
    if(idx>=this._box.length){idx=0;}
    this.changeIndex(idx);
    var eventstr = "PPTBoxHelper.instance['" this.uid "']._play()";
    this._autoplay = setInterval(eventstr,this.autoplayer*1000);
  },
  flashHTML : function(url,width,height,idx) {
    var isFlash = url.substring(url.lastIndexOf('.') 1).toLowerCase()=="swf";
    var html = "";
    if(isFlash){
      html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "
        "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" width "' height='" height "'>"
        "<param name="movie" value="" url "" />"
        "<param name='quality' value='high' />"
        "<param name='wmode' value='transparent'>"
        "<embed src='" url "' quality='high' wmode='opaque' pluginspage='http://www.macromedia.com/go/getflashplayer'"
       " type='application/x-shockwave-flash' width=" width " height='" height "'></embed>"
       " </object>";
    } else {
      var eventstr = "PPTBoxHelper.instance['" this.uid "']";
      var style = "";
      if(this._box[idx].href){
        style = "cursor:pointer"
      }
      html="<img src='" url "' style='width:" width "px;height:" height "px;" style "' onclick = "" eventstr ".clickPic(" idx ")"/>";
    }
    return html;
  },
  changeIndex : function(idx){
    var parame = this._box[idx];
    moveElement(this.uid "_flashbox",-(idx*this.width),1);
    var imgs = this._$(this.uid "_imagebox").getElementsByTagName("div");
    imgs[this._box.length-1-this._curIndex].className = "bitdiv defimg";
    imgs[this._box.length-1-idx].className = "bitdiv curimg";
    this._curIndex = idx;
  },
  mouseoverPic:function(idx){
    this.changeIndex(idx);
    if(this.autoplayer>0){
      clearInterval(this._autoplay);
      var eventstr = "PPTBoxHelper.instance['" this.uid "']._play()";
      this._autoplay = setInterval(eventstr,this.autoplayer*1000);
    }
  },
  clickPic:function(idx){
    var parame = this._box[idx];
    if(parame.href&&parame.href!=""){
      window.open(parame.href,this.target);
    }
  },
  add:function (imgParam){
    this._box[this._box.length] = imgParam;
  },
  show : function () {
    this._createMainBox();
    this._init();
    if(this.autoplayer>0){
      var eventstr = "PPTBoxHelper.instance['" this.uid "']._play()";
      this._autoplay = setInterval(eventstr,this.autoplayer*1000);
    }
  }
}
var PPTBoxHelper =
{
  count: 0,
  instance: {},
  getId: function() { return '_ppt_box-'   (this.count  ); }
};
function moveElement(elementID,final_x,interval) {
 if (!document.getElementById) return false;
 if (!document.getElementById(elementID)) return false;
 var elem = document.getElementById(elementID);
 if (elem.movement) {
  clearTimeout(elem.movement);
 }
 if (!elem.style.left) {
  elem.style.left = "0px";
 }
 var xpos = parseInt(elem.style.left);
 if (xpos == final_x ) {
    return true;
 }
 if (xpos < final_x) {
  var dist = Math.ceil((final_x - xpos)/5);
  xpos = xpos   dist;
 }
 if (xpos > final_x) {
  var dist = Math.ceil((xpos - final_x)/5);
  xpos = xpos - dist;
 }
 elem.style.left = xpos   "px";
 var repeat = "moveElement('" elementID "'," final_x "," interval ")";
 elem.movement = setTimeout(repeat,interval);
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.jb51.net 点击循环切换内容</title>
  <style>
    a {
      cursor: pointer;
      color: red;
    }
    p {
      display: none;
    }
  </style>
</head>
<body>
  <a onclick="con()">循环切换内容</a>
  <p>11111</p>
  <p>22222</p>
  <p>33333</p>
  <script>
    //可以换成切换图片等等
    flag = 0;
    pre = 0;
    function con(){
      var cons = document.getElementsByTagName("p");
      document.getElementsByTagName("p")[pre].style.display = "none";
      document.getElementsByTagName("p")[flag].style.display = "inline";
      console.log(flag);
      pre = flag;
      if(flag == cons.length - 1) { //注意是cons.length-1,因为索引值是从0开始的
        flag = 0;
      } else {
          flag;
      }
    }
  </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>www.jb51.net 点击链接切换显示隐藏内容</title>
 <style>
  a {
   cursor: pointer;
   color: red;
  }
  #p1, #p2 {
   display: none;
  }
 </style>
</head>
<body>
 <a onclick="con(1)">显示内容1</a>
 <a onclick="con(2)">显示内容2</a>
 <p id="p1">11111</p>
 <p id="p2">22222</p>
 <script>
  flag = "p1";
  function con(i){ //参数传递时传递字符串似乎有问题,这里采用的是数字传参
   document.getElementById(flag).style.display = "none";
   document.getElementById("p"   i).style.display = "inline";
   flag = "p"   i;
  }
 </script>
</body>
</html>

职能图如下:

越多关于JavaScript相关内容感兴趣的读者可查阅本站专项论题:《JavaScript切换特效与才具总计》、《JavaScript遍历算法与技术总括》、《JavaScript查找算法技艺总括》、《JavaScript错误与调整技艺总括》、《JavaScript数据结构与算法本领总括》及《JavaScript数学生运动算用法总计》

越多关于JavaScript相关内容感兴趣的读者可查阅本站专项论题:《JavaScript切换特效与技巧计算》、《JavaScript遍历算法与本事总计》、《JavaScript查找算法技巧总计》、《JavaScript错误与调度技能总括》、《JavaScript数据结构与算法技术总括》及《JavaScript数学生运动算用法总计》

Web前端 3

企望本文所述对大家JavaScript程序设计有所援救。

指望本文所述对大家JavaScript程序设计有着扶助。

更加多关于JavaScript相关内容感兴趣的读者可查阅本站专项论题:《JavaScript切换特效与技巧总括》、《JavaScript查找算法技能总结》、《JavaScript动画特效与本领汇总》、《JavaScript错误与调度工夫计算》、《JavaScript数据结构与算法技能计算》及《JavaScript数学生运动算用法总结》

你或者感兴趣的篇章:

  • javascript点击开关实现掩饰突显切换效果
  • js点小图展现大图的切换来效代码
  • 用javascript实现的图片布里Stowe克后出示并切换加文字效率
  • 用javascript达成图片惠灵顿克后出示并切换
  • 文字眨眼之间间从左到右切换展现的JavaScript代码
  • JS实现的幻灯片切换突显效果
  • js图片模糊切换呈现特效的章程
  • vue.js 左边二级菜单展现与潜伏切换的实例代码
  • JS轻便兑现tab切换效果的多窗口显示效果
  • 原生JS完毕遮蔽展现图片 JS实现点击切换图片效果
  • JS达成点击链接切换展现隐蔽内容的措施

你大概感兴趣的稿子:

  • javascript点击开关完结隐敝展现切换效果
  • Web前端,js点小图彰显大图的切换到效代码
  • 用javascript实现的图样纽伦堡克后显得并切换Gavin字成效
  • 用javascript实现图片马普托克后显得并切换
  • 文字刹那间从左到右切换突显的JavaScript代码
  • JS完毕的幻灯片切换显示效果
  • js图片模糊切换展现特效的秘诀
  • vue.js 侧边二级菜单呈现与遮蔽切换的实例代码
  • JS轻便兑现tab切换效果的多窗口体现效果
  • 原生JS完结掩盖显示图片 JS完结点击切换图片效果
  • JS完结点击循环切换展现内容的法门

可望本文所述对大家JavaScript程序设计有所协助。

你大概感兴趣的篇章:

  • javascript点击开关完结隐敝展现切换效果
  • js点小图彰显大图的切换作用代码
  • 用javascript落成的图形埃德蒙顿克后出示并切换Gavin字作用
  • 用javascript完毕图片奥兰多克后出示并切换
  • 文字须臾间从左到右切换展现的JavaScript代码
  • js图片模糊切换展现特效的主意
  • vue.js 左侧二级菜单显示与潜伏切换的实例代码
  • JS简单兑现tab切换效果的多窗口展现效果
  • 原生JS实现隐蔽展现图片 JS实现点击切换图片效果
  • JS完成点击链接切换展现掩饰内容的秘诀
  • JS完成点击循环切换显示内容的艺术
TAG标签:
版权声明:本文由澳门新葡8455手机版发布于Web前端,转载请注明出处:JS完成点击循环切换突显内容的主意,JS完成点击