用js实现类似分享到显示效果
效果在左边的那个蓝色方块:进入显示的时候,会显示“分享到”几个字,鼠标移上,内容会慢慢移出,鼠标移出,内容再慢慢回复原来位置。
这个要点提示部分,在前面的几篇要点中都有提到,这里就不提了。
下面,直接上代码喽:
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>无标题文档</title>
<style>
body{margin:0; padding:0; font:12px/1.5 arial;}
#share{width:100px; height:200px; line-height:200px; text-align:center; border:1p solid #ccc; background:#f5f5f5; position:absolute; left:-100px; top:100px;}
#share_tit{position:absolute; right:-20px; top:60px; width:20px; height:60px; padding:10px 0; background:#06c; text-align:center; line-height:18px; color:#fff;}
</style>
<script>
window.onload = function(){
var share = document.getElementById("share");
share.onmouseover = function(){
startrun(this,0)
}
share.onmouseout = function(){
startrun(this,-100)
}
}
var timer = null
var speed = 0;
function startrun(obj,target){
clearInterval(timer);
timer = setInterval(function(){
if(obj.offsetLeft<target){
speed = 10;
}else{
speed = -10;
}
if(obj.offsetLeft == target){
clearInterval(timer);
}else{
obj.style.left = obj.offsetLeft + speed + "px";
}
},30)
}
</script>
</head>
<body>
<div id="share">
分享到内容
<span id="share_tit">分享到</span>
</div>
</body>
</html>
我的微博 http://weibo.com/u/1650528354
博客地址 http://www.cnblogs.com/jingangel/
本博的代码都是博主边学习边写的,代码都是自己敲的,如果要复制请加上出处,谢谢!
博客地址 http://www.cnblogs.com/jingangel/
本博的代码都是博主边学习边写的,代码都是自己敲的,如果要复制请加上出处,谢谢!