link2192 link2193 link2194 link2195 link2196 link2197 link2198 link2199 link2200 link2201 link2202 link2203 link2204 link2205 link2206 link2207 link2208 link2209 link2210 link2211 link2212 link2213 link2214 link2215 link2216 link2217 link2218 link2219 link2220 link2221 link2222 link2223 link2224 link2225 link2226 link2227 link2228 link2229 link2230 link2231 link2232 link2233 link2234 link2235 link2236 link2237 link2238 link2239 link2240 link2241 link2242 link2243 link2244 link2245 link2246 link2247 link2248 link2249 link2250 link2251 link2252 link2253 link2254 link2255 link2256 link2257 link2258 link2259 link2260 link2261 link2262 link2263 link2264 link2265 link2266 link2267 link2268 link2269 link2270 link2271 link2272 link2273 link2274 link2275 link2276 link2277 link2278 link2279 link2280 link2281 link2282 link2283 link2284 link2285 link2286 link2287 link2288 link2289 link2290 link2291 link2292 link2293 link2294 link2295 link2296 link2297 link2298 link2299 link2300 link2301 link2302 link2303 link2304 link2305 link2306 link2307 link2308 link2309 link2310 link2311 link2312 link2313 link2314 link2315 link2316 link2317 link2318 link2319 link2320 link2321 link2322 link2323 link2324 link2325 link2326 link2327 link2328

[Vue.js] Check if user scrolled to bottom

I need show button backtotop only if user has scrolled bottom > 250. How I can do it?

My code:

<button v-if=”checkScroll” class=”goTop” @click=”backToTop”>
<i class=”fa fa-angle-up” aria-hidden=”true”></i>

export default {
methods: {
computed: {
checkScroll() {
if ($(document).scrollTop() > 250) {
return true;
} else {
return false;
backToTop() {

My code is not working. Errors I do not get. Button is hidden.

Solution :

Also don’t forget to destroy the event:

new Vue({
el: “#app”,
data() {
return {
scroll: null
methods: {
handleScroll(e) {
this.scroll = window.scrollY || window.scrollTop
created() {
window.addEventListener(‘scroll’, this.handleScroll);
destroyed() {
window.removeEventListener(‘scroll’, this.handleScroll);
html {
height: 3000px; /* some random height for demonstration purpose */

button {
position: fixed;
<script src=”"></script>

<!– scroll to see the button –>

<div id=”app”>
<button v-show=”scroll > 250”>foobar</button>

Solution 2:

Use the onScroll event in Javascript to detect when the user scrolls down/up and use scrollTop() to automatically move to the top of the page when the button is clicked.

Make sure it is position:fixed;.

For more info, check out these:

To show/hide the button just change it’s size using HTML DOM methods. For example:

document.getElementsByClassName(“goTop”)[0].width = 30;

Solution 3: has great sketches for in demand features like this all for free. here is a scroll to top functionality page you can tweak to fit the needs hopefully

.scrolltop-wrap {
$size: 3rem;
$offsetBottom: 2rem;
$offsetHorizontal: 2rem;
$scrollToRevealDistance: 12rem; // scroll offset to reveal scroll-to-top link

It’s all scss instead of javascript. Here is a scss to css generator you can use,