您的位置:首页 > Web前端 > JavaScript

用js实现类似分享到显示效果

2012-03-12 17:43 169 查看
效果在左边的那个蓝色方块:进入显示的时候,会显示“分享到”几个字,鼠标移上,内容会慢慢移出,鼠标移出,内容再慢慢回复原来位置。

// 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

分享到内容 分享到

这个要点提示部分,在前面的几篇要点中都有提到,这里就不提了。

下面,直接上代码喽:

<!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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: