jQuery火箭上升回到顶部效果

模板网 2014-11-17

jQuery火箭上升回到顶部效果,jQuery模拟火箭升空的效果使网页回到顶部,效果逼真。

代码打包下载:jQuery火箭上升回到顶部效果

效果截图:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
  5. <title>jQuery火箭上升回到顶部效果</title>
  6. <style>
  7. body {height:2500px;}
  8. #rocket-to-top div {
  9. left: 0;
  10. margin: 0;
  11. overflow: hidden;
  12. padding: 0;
  13. position: absolute;
  14. top: 0;
  15. width: 149px;
  16. }
  17. #rocket-to-top .level-2 {
  18. background: url(/data1/20141117/rocket_button_up.png) no-repeat scroll -149px 0 transparent;
  19. display: none;
  20. height: 250px;
  21. opacity: 0;
  22. z-index: 1;
  23. }
  24. #rocket-to-top .level-3 {
  25. background: none repeat scroll 0 0 transparent;
  26. cursor: pointer;
  27. display: block;
  28. height: 150px;
  29. z-index: 2;
  30. }
  31. #rocket-to-top {
  32. background: url(/data1/20141117/rocket_button_up.png) no-repeat scroll 0 0 transparent;
  33. cursor: default;
  34. display: block;
  35. height: 250px;
  36. margin: -125px 0 0;
  37. overflow: hidden;
  38. padding: 0;
  39. position: fixed;
  40. right: 0;
  41. top: 80%;
  42. width: 149px;
  43. z-index: 11;
  44. }
  45. </style>
  46. <script src="http://libs.baidu.com/jquery/1.8.0/jquery.min.js"></script>
  47. <script type="text/javascript">
  48. $(function() {
  49. var e = $("#rocket-to-top"),
  50. t = $(document).scrollTop(),
  51. n,
  52. r,
  53. i = !0;
  54. $(window).scroll(function() {
  55. var t = $(document).scrollTop();
  56. t == 0 ? e.css("background-position") == "0px 0px" ? e.fadeOut("slow") : i && (i = !1, $(".level-2").css("opacity", 1), e.delay(100).animate({
  57. marginTop: "-1000px"
  58. },
  59. "normal",
  60. function() {
  61. e.css({
  62. "margin-top": "-125px",
  63. display: "none"
  64. }),
  65. i = !0
  66. })) : e.fadeIn("slow")
  67. }),
  68. e.hover(function() {
  69. $(".level-2").stop(!0).animate({
  70. opacity: 1
  71. })
  72. },
  73. function() {
  74. $(".level-2").stop(!0).animate({
  75. opacity: 0
  76. })
  77. }),
  78. $(".level-3").click(function() {
  79. function t() {
  80. var t = e.css("background-position");
  81. if (e.css("display") == "none" || i == 0) {
  82. clearInterval(n),
  83. e.css("background-position", "0px 0px");
  84. return
  85. }
  86. switch (t){
  87. case "0px 0px":
  88. e.css("background-position", "-298px 0px");
  89. break;
  90. case "-298px 0px":
  91. e.css("background-position", "-447px 0px");
  92. break;
  93. case "-447px 0px":
  94. e.css("background-position", "-596px 0px");
  95. break;
  96. case "-596px 0px":
  97. e.css("background-position", "-745px 0px");
  98. break;
  99. case "-745px 0px":
  100. e.css("background-position", "-298px 0px");
  101. }
  102. }
  103. if (!i) return;
  104. n = setInterval(t, 50),
  105. $("html,body").animate({scrollTop: 0},"slow");
  106. });
  107. });
  108. </script>
  109. </head>
  110. <body>
  111. <p>请将滚动条向下拖动</p>
  112. <div style="display: none;" id="rocket-to-top">
  113. <div style="opacity:0;display: block;" class="level-2"></div>
  114. <div class="level-3"></div>
  115. </div>
  116. </body>
  117. </html>

相关文章

  1. jquery折叠效果

    jquery折叠效果,图片折叠收缩,效果非常棒! 代码打包下载: jquery折叠效果 效果图:

  2. jQuery火箭上升回到顶部效果

    jQuery火箭上升回到顶部效果,jQuery模拟火箭升空的效果使网页回到顶部,效果逼真。 代码打包下载: jQuery火箭上升回到顶部效果 效果截图:

  3. 医疗网站常用的左右滑动Banner效果_jquery插件

    医疗网站常用的左右滑动Banner效果_jquery插件,使用简单。 在线演示 使用方法: 1.在网页中引入一下代码: 复制代码 代码如下: link href=css/slide.css rel=stylesheet type=text/css / script type=text/javascript src=js/jquery.js/script script type=

  4. jQuery实现的返回顶部功能

    jQuery实现的返回顶部功能

  5. jQuery集合多种过渡效果幻灯片插件jQuery Nivo Slider v2.5.1

    好吧一直有人抱怨js版本的焦点图过渡效果太单调,今天介绍的这款jQuery插件Nivo Slider,除了一般该有的参数设置外,最大的亮点就是其集成了16种(v2.5.1)过渡效果 ,再加上对CSS的调整,效果相信已经可以和很多Flash版本的焦点图相媲美了 插件同时还支持缩略

随机推荐

  1. jquery折叠效果

    jquery折叠效果,图片折叠收缩,效果非常棒! 代码打包下载: jquery折叠效果 效果图:

  2. jQuery火箭上升回到顶部效果

    jQuery火箭上升回到顶部效果,jQuery模拟火箭升空的效果使网页回到顶部,效果逼真。 代码打包下载: jQuery火箭上升回到顶部效果 效果截图:

  3. 医疗网站常用的左右滑动Banner效果_jquery插件

    医疗网站常用的左右滑动Banner效果_jquery插件,使用简单。 在线演示 使用方法: 1.在网页中引入一下代码: 复制代码 代码如下: link href=css/slide.css rel=stylesheet type=text/css / script type=text/javascript src=js/jquery.js/script script type=

  4. jQuery实现的返回顶部功能

    jQuery实现的返回顶部功能

  5. jQuery集合多种过渡效果幻灯片插件jQuery Nivo Slider v2.5.1

    好吧一直有人抱怨js版本的焦点图过渡效果太单调,今天介绍的这款jQuery插件Nivo Slider,除了一般该有的参数设置外,最大的亮点就是其集成了16种(v2.5.1)过渡效果 ,再加上对CSS的调整,效果相信已经可以和很多Flash版本的焦点图相媲美了 插件同时还支持缩略