网站地图    收藏   

主页 > 前端 > javascript >

纯JS动画效果实现

来源:未知    时间:2014-10-27 13:31 作者:xbdadmin 阅读:

[导读] 纯JS实现动画滚动效果。 源码如下: !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 co...

纯JS实现动画滚动效果。

源码如下:


<!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>无标题文档</title>
<style type="text/css">
*{ margin:0px; padding:0px;}
#box_1{ width:200px; height:150px; background:#03F; position:absolute; left:-200px; top:0px; opacity: 0.4;  filter:Alpha(opacity=40);}
#box_1 .span_1{ display:block; width:20px; height:30px; position:absolute; right:-20px; top:50%; margin-top:-15px;}
</style>
</head>
<body>
 
<div id="box_1">
<span class="span_1">公告</span>
 
</div>
<script language="javascript">
window.onload = function(){
var box_1 = document.getElementById('box_1');
box_1.onmouseover = function(){
start_animate(10,0);
}
box_1.onmouseout = function(){
start_animate(-10,-200);
}
 
}
 
var times = null;
function start_animate(spend,iTarget){
//console.log(spend,iTarget);
clearInterval(times);
var box_1 = document.getElementById('box_1');
times = setInterval(function(){
box_1_l = box_1.offsetLeft;
//console.log(box_1_l);
if(box_1_l == iTarget){
clearInterval(times);
}else{
box_1.style.left = box_1.offsetLeft+spend+'px';
}
},30);
 
}
 
</script>
 
 
 
</body>
</html>
 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论