Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Scroll to top functionality not working on Firefox

I am using this

$(function() {
  $('<button onclick="topFunction()" id="topBtn" title="Go to top"></button>').insertAfter('div#mw-content-text');
});

// When users scroll down 100px, show the Top button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
    document.getElementById("topBtn").style.display = "block";
  } else {
    document.getElementById("topBtn").style.display = "none";
  }
}

// When users click on Top button, scroll up
function topFunction() {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
}

Which works fine on all browsers apart from Firefox. In this case, it is displayed in the middle of the screen and does not stick at the bottom right when scrolling.

The css I use is this:

#topBtn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 99;
  font-size: 16px;
  border: none;
  outline: none;
  background-color: rgba(0, 0, 0, 0.3);
  color: white;
  cursor: pointer;
  padding: 20px;
  border-radius: 4px;
}
#topBtn:hover {
  background-color: #555;
}
#topBtn:before {
    position: fixed;
    bottom: 2px;
    right: 36px;
    color: #fff;
    font-size: 42px;
    font-family: 'Georgia';
    content: "^";
    font-weight: 600;
}

Reference page: https://lsj.gr/wiki/%CE%BB%CE%BF%CF%8D%CF%89

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to add position: fixed; to the button. Then you can position it with left, right, bottom and top.

$(function() {
  $('<button onclick="topFunction()" id="topBtn" title="Go to top">Click</button>').insertAfter('div#mw-content-text');
});
#mw-content-text {
  height: 100px;
  width: 100px;
  background: green;
}

#topBtn {
  position: fixed;
  right: 30px;
  bottom: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="mw-content-text"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!