npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-3-scroll-to-top-button

v1.0.2

Published

Vue.js 3 component to scroll on the top on the page, with good animation and UI

Downloads

4

Readme

vue-3-scroll-to-top-button

A Vue.js component for a floating action button (FAB) that scrolls the page to the top.

Installation

Install the package using npm or yarn:

npm install vue-3-scroll-to-top-button
# or
yarn add vue-3-scroll-to-top-button

Default example

By default, the button will be on the bottom left, you can play with the options to customize it or positionnate it.

Demo

<script setup lang="ts">
import { ScrollToTopButton } from 'vue-3-scroll-to-top-button';
import 'vue-3-scroll-to-top-button/style.css';
</script>

<template>
  <ScrollToTopButtonVue />
</template>

Example with relative position

You can for example pass props to positionnate relatively the button

Demo1

<script setup lang="ts">
import { ScrollToTopButton } from 'vue-3-scroll-to-top-button';
import 'vue-3-scroll-to-top-button/style.css';
</script>
<template>
  <ScrollToTopButtonVue 
    noTeleport 
    :showButtonTreshold="0" 
    :style="{ position: 'relative' }"
  />
</template>

Example with Custom Icon

Or you can take advantage of the slot to pass a custom icon, or play with the detection treshold

Demo2

<script setup lang="ts">
import { ScrollToTopButton } from 'vue-3-scroll-to-top-button';
import 'vue-3-scroll-to-top-button/style.css';
</script>
<template>
  <div>
  <ScrollToTopButtonVue 
    :showButtonTreshold="300" 
    position="top" 
    class="custom-button" 
    backgroundColor="yellow"
    iconColor="blue"
    >      
      <template #icon>
        <svg viewBox="0 0 24 24" width="48px" height="48px" fill="#ffffff" xmlns="http://www.w3.org/2000/svg">
          <path d="M12 2L3 12h4v8h10v-8h4z" />
        </svg>
      </template>
    </ScrollToTopButtonVue>
  </div>
</template>
<style>
.custom-button {
  height: 100px;
}
</style>

Props

|Name |Type | Description | |---|---|---| |anchor | (string) | The target element to which the button will be teleported. Defaults to 'body'. | |iconColor | (string) | The color of the button icon. Defaults to 'white'. | |backgroundColor | (string) | The background color of the button. Defaults to '#2C3436'. | |showButtonTreshold | (number) | The scroll threshold at which the button becomes visible. Defaults to 1. | |withAnimation | (boolean) | Enables or disables the transition animation. Defaults to true. | |size | (ButtonSize) | The size of the button. Can be 'small', 'medium', or 'large'. Defaults to 'medium'. | |position | (ButtonPosition) | The position of the button. Can be 'top-left', 'top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', or 'left'. Defaults to 'bottom-right'. | |noTeleport | (boolean) | Disables teleporting the button to a specified anchor. Defaults to false. | |marginFromSide | (string) | The margin from the side when using noTeleport. Defaults to '12px'. |

Types

The component is fully written in typescript so you have the best autocompletion Here are the types of the props so you can manipulate it.

export type ButtonSize = 'small' | 'medium' | 'large'

export type ButtonPosition = 'top-left' 
  | 'top' 
  | 'top-right' 
  | 'right' 
  | 'bottom-right'
  | 'bottom'
  | 'bottom-left'
  | 'left'

export interface ScrollToTopButtonProps {
  anchor?: string
  iconColor?: string
  backgroundColor?: string
  showButtonTreshold?: number
  withAnimation?: boolean
  size?: ButtonSize
  position?: ButtonPosition
  noTeleport?: boolean
  marginFromSide?: string
}

Accessibility

The component is designed to be accessible with proper ARIA attributes and roles. The button is given an aria-label of "Scroll to Top" and a role of "button" to enhance accessibility.

Transitions

The button features a smooth transition effect when appearing or disappearing, enhancing the user experience.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Thanks to Anatole Acqueberge for creating this amazing Vue 3 confettis plugin! Feel free to contribute, report issues, or suggest improvements. Happy coding! 🎉