找回密码
 免费注册

回到顶部或者底部前端html+css+js综合案例

[复制链接]
发表于 2023-1-27 19:59:09 | 显示全部楼层 |阅读模式
回到顶部或者底部前端html+css+js综合案例

代码如下:
  1. <style>
  2. .uptodown {
  3.     outline: none;
  4.     position: fixed;
  5.     background-color: #fff;
  6.     width: 40px;
  7.     height: 40px;
  8.     color: #999;
  9.     display: flex;
  10.     align-items: center;
  11.     justify-content: center;
  12.     font-size: 20px;
  13.     box-shadow: 0 0 6px rgba(0,0,0,.12);
  14.     cursor: pointer;
  15.     z-index: 5
  16. }

  17. .d-fixed {
  18.     right: 70px;
  19.         width: 50px;
  20. }
  21. @media (max-width: 992px) {
  22. .d-fixed {
  23.     right: 0px;
  24. }

  25. }
  26. </style>
  27. <div id="scroll_to_top" class="d-fixed " style="position: fixed; _position: absolute; bottom: 180px;   height: 0px;display: none;">
  28.         <a href="javascript:void(0);" class="uptodown" title="回到顶部"><i class="icon-angle-up"></i></a>
  29. </div>
  30. <div id="scroll_to_end" class="d-fixed " style="position: fixed; _position: absolute; bottom: 80px;   height: 50px;display: none;">
  31.         <a href="javascript:void(0);" class="uptodown" title="直达底部"><i class="icon-angle-down"></i></a>
  32. </div>

  33. <script>
  34. //回到顶部
  35. var jscroll_to_top = $('#scroll_to_top');
  36. $(window).scroll(function() {
  37.         if ($(window).scrollTop() > 0) {
  38.            jscroll_to_top.fadeIn('slow');
  39.         } else {
  40.                 jscroll_to_top.fadeOut('slow');
  41.         }
  42. });
  43. jscroll_to_top.on('click', function() {
  44.         $('html,body').animate({scrollTop: 0}, 'slow');
  45. });
  46. //直达底部
  47. var jscroll_to_end = $('#scroll_to_end');
  48. $(window).scroll(function() {
  49.         if ($(window).scrollTop() < ($(document).height()-$(window).height()) ) {
  50.            jscroll_to_end.fadeIn('slow');
  51.         } else {
  52.                 jscroll_to_end.fadeOut('slow');
  53.         }
  54. });
  55. jscroll_to_end.on('click', function() {
  56.         $('html,body').animate({scrollTop: $(document).height() }, 'slow');
  57. });
  58. </script>
复制代码


QQ|Archiver|小黑屋|网站地图|深圳市金黑网络技术有限公司 ( 粤ICP备2021124338号|粤公网安备 44030702003689号 )

GMT+8, 2026-8-8 18:05 , Processed in 0.048420 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表