1.0.2 • Published 3 years ago

vue-to-top-button v1.0.2

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

vue-to-top-button

A simple custom plugin for Vue and Nuxt projects, that embeds a "to-top" button on a page. The plugin is easily customizable for the appearance of the page. It is possible to automatically connect a button to all pages or connect to individual pages using a directive.

Type 0 button Type 1 animated button

Installation

npm install vue-to-top-button --save

Usage Vue

Import statement:

If use mixin (auto connection)

// Your main.js code
import vueToTopButton from "vue-to-top-button"
Vue.use(vueToTopButton)

//or with options
Vue.use(vueToTopButton, {
    //options
})

If use directive:

// Your main.js code
import vueToTopButton from "vue-to-top-button"
Vue.use(vueToTopButton, {
    auto: false,
    //other options
})
// Your App.vue code
<template>
  <div id="app">
   ...  
   <div v-totopbutton></div>
  </div>
</template>

Usage Nuxt

Import statement:

If use mixin (auto connection)

// Create vueToTopButton.js in plugins directory
// Your vueToTopButton.js code
import Vue from 'vue'
import vueToTopButton from "vue-to-top-button";
export default function (app) {
  if (!Vue.prototype.vueToTopButton) {
    Vue.use(vueToTopButton)
  }
}

//or with options
Vue.use(vueToTopButton, {
    //options
})

// Your nuxt.config.js
module.exports = {
    plugins: [
        {src: '~/plugins/vueToTopButton.js',  ssr: false}
    ],
    ...
}

If use directive:

// Create vueToTopButton.js in plugins directory
// Your vueToTopButton.js code
import Vue from 'vue'
import vueToTopButton from "vue-to-top-button";
export default function (app) {
  if (!Vue.prototype.vueToTopButton) {
    Vue.use(vueToTopButton, {
        auto: false,
        //other options
    })
  }
}

// Your nuxt.config.js
module.exports = {
    plugins: [
        {src: '~/plugins/vueToTopButton.js',  ssr: false}
    ],
    ...
}
// Your any-page.vue or any-layout.vue code
<template>
  <div>
   ...  
   <div v-totopbutton></div>
  </div>
</template>

OPTIONS

PropertyTypeDescription
autobooleanChoose to use directive or mixin mode. If set to true, the button connects automatically to all pages. If set to false, then you need to use the totopbutton directive on any page. Default true
typenumberButton appearance. 0 - Static button (no animation). 1 - Animated button. Default 0
colorstringButton color. Default "#777"
widthnumberThe size of the button in pixels. Default 50
offsetnumberNumber of scrolled screens before the button appears. Default 1.7
bgstringThe fill color of the button. Default "transparent"
radiusnumberButton border radius as a percentage. Default 50
bottomnumberBottom padding in pixels. Default 70
rightnumberRight indent in pixels. Default 70
transitionnumberSmoothness of appearance in milliseconds. Default 300
animationnumberAnimation speed in seconds (for buttons with animation). Default 2.5
classnamestringAdditional class. Default ""

EXAMPLE WITH OPTIONS

alt text

Vue.use(vueToTopButton, {
    type: 1,
    color: "#02989a",
    bg: "#d2f7f3",
    offset: 2
})