SoFunction
Updated on 2025-04-10

jQuery implements the return to the top button and scrolling function [with animation effect]

jQuery script:

 <script type="text/javascript">
     $(function() {
       var scrollDiv = ('div');
       $(scrollDiv).attr('id', 'toTop').html('^ Back to top').appendTo('body');
       $(window).scroll(function() {
         if ($(this).scrollTop() != 0) {
           $('#toTop').fadeIn();
         } else {
           $('#toTop').fadeOut();
         }
       });
       $('#toTop').click(function() {
         $('body,html').animate({ scrollTop: 0 }, 800);
       })
     });
   </script>

CSS style:

<style type="text/css">
     #toTop
 {
       width: 100px;
       z-index: 10;
       border: 1px solid #333;
       background: #121212;
       text-align: center;
      padding: 5px;
      position: fixed;
       bottom: 0px;
       right: 0px;
       cursor: pointer;
      display: none;
      color: #fff;
       text-transform: lowercase;
       font-size: 0.9em;
 }
  </style>

Scrolling operation with iframe frame:

&lt;script type="text/javascript"&gt;
 &lt;!--
     $().ready(function() {
       $('&lt;div  class="btn_return_old" style="position:' + ($. ? "absolute" : "fixed") + ';" onclick="return_old({$feedback_flag},\'{$current_url}\')">Return to the old version</div>').appendTo($("body"));
       if ($.) {
        $("#return_old_tips").css("top", 200);
      }
      if ($.) {
         = function() {
          var f = 200 + ( || );
          if (f &gt; parseInt($("body").height(), 10)) {
            f = parseInt($("body").height(), 10);
          }
           $("#return_old_tips").css({
            top: f,
            left: 0
           });
        }
          = ;
      } else {
        $().scroll(function() {
           var f = 200 + ( || );
          if (f &gt; parseInt($("body").height(), 10)) {
            f = parseInt($("body").height(), 10);
          }
          $("#return_old_tips").css({
            top: f,
             left: 0
           });
        }).resize(function() {
           var f = 200 + ( || );
           if (f &gt; parseInt($("body").height(), 10)) {
            f = parseInt($("body").height(), 10);
          }
          $("#return_old_tips").css({
            top: f,
             left: 0
           });
         });
       }
     });
 //--&gt;
   &lt;/script&gt;

The above is the jQuery implementation of the button back to the top and scroll scroll function [with animation effect] introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!