免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1428 | 回复: 1
打印 上一主题 下一主题

jquery简单实现微博广场下滑效果 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-10 15:34 |只看该作者 |倒序浏览
jquery简单实现微博广场下滑效果








Html代码
  1. 1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. 2.<html xmlns="http://www.w3.org/1999/xhtml">  
  3. 3.    <head>  
  4. 4.        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. 5.        <title>jQuery下滑效果</title>  
  6. 6.        <style type="text/css">  
  7. 7./*css也是重要的*/   
  8. 8.#container {   
  9. 9.    height: 540px;   
  10. 10.    width: 358px;   
  11. 11.    overflow: hidden;   
  12. 12.}   
  13. 13.  
  14. 14./*外面容器高度为400px,超过时不显示*/   
  15. 15.#container p {   
  16. 16.    border: 1px dotted #333366;   
  17. 17.    padding: 10px;   
  18. 18.    margin-bottom: 10px;   
  19. 19.    width: 335px;   
  20. 20.    height: 70px;   
  21. 21.}   
  22. 22.</style>  
  23. 23.        <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>  
  24. 24.        <script type="text/javascript">  
  25. 25.    /*-需要:引入一个jquery的包-原理:隐藏第一组<p></p>标签(包含里面的内容),然后用slideDown效果渐渐下滑显示出来再把最后一组<p></p>标签插入到最前面并隐藏,形成循环*/   
  26. 26.    $(function(){   
  27. 27.        var interval = 3000;   
  28. 28.        var slide = setInterval(slideIt,interval);   
  29. 29.        $("#container").mouseover(function(){   
  30. 30.            clearInterval(slide);//当鼠标移上去的时候停止下滑   
  31. 31.        }).mouseout(function(){   
  32. 32.            slide = setInterval(slideIt,interval);//当鼠标移开的时候继续下滑   
  33. 33.        });   
  34. 34.        //slideIt();   
  35. 35.    });   
  36. 36.  
  37. 37.  
  38. 38.    function slideIt(){   
  39. 39.        var obj = $("#container p");//定义一个变量obj,把id为container里的所有<p></p>标签赋给它   
  40. 40.  
  41. 41.        /*版本1   
  42. 42.      
  43. 43.        obj.first().slideDown(5000);//让id为container里的第一个div以5000毫秒(5秒)的速度下滑(这个p默认是隐藏的   
  44. 44.      
  45. 45.        obj.last().insertBefore(obj.first()).hide();//把id为container里的最后一组<p></p>标签插到最前面(这样容器里的<p></p>标签就可以循环起来)并隐藏   
  46. 46.      
  47. 47.        */   
  48. 48.      
  49. 49.        /*版本2*/   
  50. 50.      
  51. 51.        obj.last().hide().prev().hide();//倒数2个隐藏   
  52. 52.      
  53. 53.        obj.last().insertBefore(obj.first()).fadeIn(1000);//把id为container里的最后一组<p></p>标签插到最前面(这样容器里的<p></p>标签就可以循环起来)并以1秒速度淡出   
  54. 54.      
  55. 55.        obj.eq(0).hide().slideDown(300);//第1个p淡出   
  56. 56.  
  57. 57.        obj.eq(4).fadeOut(500);//第5个p淡出   
  58. 58.  
  59. 59.    };   
  60. 60.      
  61. 61.</script>  
  62. 62.    </head>  
  63. 63.    <body>  
  64. 64.        <div id="container">  
  65. 65.            <p>some msg here 1...</p>  
  66. 66.            <p>some msg here 2...</p>  
  67. 67.            <p>some msg here 3...</p>  
  68. 68.            <p>some msg here 4 ...</p>  
  69. 69.            <p>some msg here 5 ...</p>  
  70. 70.            <p>some msg here 6 ...</p>  
  71. 71.            <p>some msg here 7 ...</p>  
  72. 72.        </div>  
  73. 73.        <!--结束-->  
  74. 74.    </body>  
  75. 75.</html>
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-01-10 15:42 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP