请教一个DIV慢慢展现出来的效果

ldg9tpl 2012-06-29 11:18:36
是这样的,我做了一个交友站,为了更好的留住来访用户。

我想这样做,在网页顶部预先设置好一个DIV,并命名id="div123",DIV的内容文字大概是这样的:

亲爱的朋友,你知道吗?本站发信看信都是免费的,不花一分钱,你怎么不加入呢?
无帐号点击这里注册,有帐号点击这里登录


并且把这个DIV设置为隐藏,即style="height:300px;display:none",然后在首次加载中进行判断,如果用户已经登录,则该DIV不显示出来。

如果说用户未登录,则让这个DIV展示出来,即style="display:block"。

为了更方便大侠们帮我,我把代码帖一下
JS代码——
<script type="text/javascript">
<!--
function abc()
{
document.getElementById('div123').style.display='none';
}
-->
</script>

后台CS代码——
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["flag"] == null)  //如果尚未登录,Session["flag"]=true,表明已建立登录状态
{
Page.RegisterStartupScript("a", "<script type='text/javascript'>abc();</script>"); //展示提示DIV
}
}
}


现在我想要的效果是这样的:
1、延时展示:判断用户未登录后,并不立即展开div123,而是10秒钟后才慢慢展开。
2、div123展开的效果不是非常突然的展示,而是从高度0慢慢的展开到预定的高度300px。
3、div123展开后,有一个闭关按钮,用户点击关闭,div123从高度300px慢慢的减缩到0。如果用户不主动点击关闭按钮,那么div123完全展开后,停留10秒,然后div123又自动的慢慢的从高度300PX减缩到0。

这个效果,就与几大门户网站的顶部广告的展开关闭效果类似。

请问各位大侠,这样的效果该怎么做呢?
最好帮我写写代码,如果不想写的话,有网址也请推荐一下,谢谢啦!
非常感谢,祝大家快乐,美女天天围着转不停哈,呵呵……



...全文
495 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qxyywy 2012-06-30
  • 打赏
  • 举报
回复
jquery 的hide show
No4000 2012-06-30
  • 打赏
  • 举报
回复
jquery可以做到这样的效果
huangwenquan123 2012-06-30
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<style type="text/css">
*{margin:0px auto}
body{margin:0px auto 0px auto;text-align:center;padding:0px;}
</style>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#div123").slideDown("slow",function(){
setTimeout(function(){
$("#div123").slideUp("slow");
},2000);
})
})
</script>
</head>
<body>
<div id="div123" style="width:980px;height:50px;background:red;display:none;">a<br />b<br />c<br /></div>
<div style="width:980px;height:1000px;background:black;color:#fff">def</div>
</body>
</html>
huangwenquan123 2012-06-30
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<style type="text/css">
*{margin:0px auto}
body{margin:0px auto 0px auto;text-align:center;padding:0px;}
</style>
</head>
<body>
<div id="div123" style="width:980px;height:50px;background:red;display:block;margin-top:-50px;">a<br />b<br />c<br /></div>
<div style="width:980px;height:1000px;background:black;color:#fff">def</div>
<script type="text/javascript">
var obj = document.getElementById("div123");
var height=-50,current;
var Timer;
obj.style.display="block";
Timer=setInterval(SlideDown,10);
function SlideDown(){
current = GetHeight(obj);
if(current>=0){
clearInterval(Timer);
setTimeout(function(){
Timer = setInterval(SlideUp,10);
},2000);
}
else{
current++;
SetHeight(current);
}
}
function SlideUp(){
if(current<=height){
clearInterval(Timer);
}
else{
current--;
SetHeight(current);
}
}
function GetHeight(){
return parseInt(obj.style.marginTop);
}
function SetHeight(h){
obj.style.marginTop=h+"px";
}
</script>
</body>
</html>
happytonice 2012-06-30
  • 打赏
  • 举报
回复
用jquery

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
$("p").fadeOut(1000);
});
$(".btn2").click(function(){
$("p").fadeIn(1000);
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button class="btn1">Hide</button>
<button class="btn2">Show</button>
</body>
</html>
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
最好帮我写写代码,如果不想写的话,有网址也请推荐一下,谢谢啦!
非常感谢,祝大家快乐,美女天天围着转不停哈,呵呵……
[/Quote]

推荐的就是你说的“几大网站”。你可以完整下载其网页,然后重用其javascript代码。

使用flash或者silverlight开发更好。
licai1210 2012-06-30
  • 打赏
  • 举报
回复
http://www.cnblogs.com/ruibo/archive/2009/06/18/jquery.html

然后LZ看下JS的setTimeout还有JQ的基本操作
ldg9tpl 2012-06-30
  • 打赏
  • 举报
回复
结帖了,非常感谢7楼哥们,代码非常给力,所有浏览器都兼容

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧