d抖动效果应用场景较多,比如登陆框,当输入用户名或者密码错误的时候,出现抖动效果,提示明显,且有动感,下面就是一段空元素抖动的代码实例,希望能够给大家带来一定的帮助。

代码实例如下:
   [ 其他 ] 运行代码    下载代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>js实现的元素抖动效果</title>
<style type="text/css">
#control {
  height:100px;
  width:100px;
  background:gray;
}
</style>
<script type="text/javascript">
function shake(e,onComplete,distance,interval){
  if(typeof e==="string"){
    e=document.getElementById(e);
  }
  distance=distance||8;
  interval=interval||800;
  var originalStyle=e.style.cssText;
  e.style.position="relative";
  var start=(new Date()).getTime();
  animate();
  function animate(){
    var now=(new Date()).getTime();
    var elapsed=now-start;
    var progress=elapsed/interval;
    if(progress<1){
      var y=distance*Math.sin(Math.PI*progress*4);
      var x=distance*Math.cos(Math.PI*progress*4);
      e.style.left=x+"px";
      e.style.top=y+"px";
      setTimeout(animate, Math.min(25, elapsed));
    } 
    else{
      e.style.cssText=originalStyle;
      if(onComplete){
        onComplete(e);
      }
    }
  }
} 
window.onload=function(){
  var control=document.getElementById("control");
  control.onclick=function(){shake(this)}
}
</script>
</head>
<body>
<div id="control"> </div>
</div>
</body>
</html>

代码描述:JavaScript抖动效果。JavaScript抖动效果



157 209



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册



×
×
51前端

注册

×
绑定手机

请绑定手机号,在继续操作

×
单次下载支付

应付金额:279

支付完成后,回到下载页面,在进行下载

官方QQ群
意见反馈
qq群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到