js 中的睡眠函数

JavaScript08

js 中的睡眠函数,第1张

let array = [[{'level':"赛程表1",'time':3000},{'level':"对阵图1",'time':8000},{'level':"小组积分赛1",'time':10000}],[{'level':"赛程表2",'time':5000},{'level':"对阵图2",'time':8000},{'level':"小组积分赛2",'time':10000}],[{'level':"赛程表3",'time':5000},{'level':"对阵图3",'time':6000},{'level':"小组积分赛3",'time':9000}]]

async function sleep(time) {

  await new Promise((resolve,reject)=>{

     setTimeout(() => {

      //  console.log(`等了${time}s`)

       resolve()

     }, time)

  })

}

async function doSome(params) {

  for (let x = 0 x < array.length x++) {

    const eleArr = array[x]

    for (let y = 0 y < eleArr.length y++) {

      const ele = eleArr[y]

      console.log(ele.level)

      await sleep(ele.time)

      if (x>=array.length-1 && y>=eleArr.length-1) {

        doSome()

      }

    }

  }

}

doSome()

利用鼠标上移、移动、移出事件来控制图片的展示,实现两图对比

这个也可以用于图片的遮罩、虚化等处理

[demo展示中心]: https://yomonah.github.io/project/app.html#/location

[源码]: https://github.com/yomonah/react-demo/tree/master/src/components/picture

<script>

var class_name=function()

{

this.top=500//与顶部距离

//左侧广告

this.l_width=100//宽

this.l_height=100//高

this.l_left=100//与左侧的距离

this.l_src="http://img.baidu.com/img/logo-zhidao.gif"//图片路径

this.l_url="http://www.baidu.com/"//图片链接地址

//右侧广告

this.r_width=100//宽

this.r_height=100//高

this.r_right=100//与右侧的距离

this.r_src="http://img.baidu.com/img/logo-zhidao.gif"//图片路径

this.r_url="http://www.baidu.com/"//图片链接地址

}

var c=new class_name()

document.write('<div id="xf_left_gg" style="position:absolutewidth:'+c.l_width+'pxheigth:'+c.l_height+'pxleft:'+c.l_left+'pxtop:'+c.top+'px"><a href="'+c.l_url+'" target="_blank"><img src="'+c.l_src+'" width="'+c.l_width+'" height="'+c.l_height+'" border="0"></a></div>')

document.write('<div id="xf_right_gg" style="position:absolutewidth:'+c.r_width+'pxheigth:'+c.r_height+'px" right:'+c.r_right+'pxtop:'+c.top+'px"><a href="'+c.l_url+'" target="_blank"><img src="'+c.l_src+'" width="'+c.l_width+'" height="'+c.l_height+'" border="0"></a></div>')

function lxs_xf()

{

var t=(document.body.scrollTop>0)?(parseInt(document.body.scrollTop)+c.top):c.top

$("xf_left_gg").style.left=c.l_left+"px"

$("xf_left_gg").style.top=t+"px"

$("xf_right_gg").style.right=c.r_right+"px"

$("xf_right_gg").style.top=t+"px"

}

function $(id){return document.getElementById(id)}

if(window.attachEvent)

{

window.attachEvent("onload",lxs_xf)

window.attachEvent("onscroll",lxs_xf)

}

else

{

window.addEventListener("load",lxs_xf,false)

window.addEventListener("scroll",lxs_xf,false)

}

</script>