Git Product home page Git Product logo

xns-seek-bar's Introduction

James Sinkala ๐Ÿ‘Š

  • ๐ŸŒ My website - jamesinkala.com
  • ๐Ÿ”ญ Iโ€™m currently working on:
  • ๐ŸŒฑ Iโ€™m currently learning Rust.
  • ๐Ÿ“ I do some writting on My Blog & Dev.to.
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate on anything interesting
  • ๐Ÿ’ฌ Ask me about pretty much anything [but.. don't expect an answer to everything]
  • โšก Fun fact: I'm still learning lots of stuff

๐Ÿ“ซ Where else to find me on the www


Projects and Dev Stuff

โšก Github Stats
โ˜„๏ธ Github Streaks
๐Ÿง‘โ€๐Ÿš€ Open Source Projects
๐Ÿ’ป Projects ๐ŸŒŸ Stars ๐Ÿด Forks ๐Ÿ› Issues ๐Ÿ”” Pull Requests ๐Ÿ‘จโ€๐Ÿ’ป Language
๐ŸŽต xns-audio-player Stars Forks Issues Pull Requests Language
๐Ÿ“ฌ turqw-newsletter Stars Forks Issues Pull Requests Language
๐Ÿ“ค vue-cloudinary-uploader Stars Forks Issues Pull Requests Language
๐ŸŽต xns-audio-player-simple Stars Forks Issues Pull Requests Language
โณ xns-seek-bar Stars Forks Issues Pull Requests Language
๐Ÿ”— Reliable Link Shortener Stars Forks Issues Pull Requests Language
๐Ÿ‘ถ vuenoob/code-examples Stars Forks Issues Pull Requests Language

xns-seek-bar's People

Contributors

dependabot[bot] avatar xinnks avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

xns-seek-bar's Issues

Suggestion - tweek the mouse move behaviour

Hi @xinnks, first of all thanks for that medium article it was very helpful to me. Then I decided to give this one a go due to it's simplicity and I could not use it due to just one small issue that I found - it does not account for mouse move outside of the wrapper div.

For example if you have a really slim wrapper div like mine,

Screenshot from 2020-12-03 12-46-47

then it is hard to keep the mouse pointer in it, so I needed a way of updating the progress during mousemove event outside the wrapper div.

I ended up doing component on my own based on your article with some small changes to it for handling this. Here is my local component:

<template>
    <div class="h-8 flex items-center cursor-pointer" ref="slider">
        <div class="w-full h-1 bg-white-25 rounded-full">
            <div class="rounded-full h-1 bg-white-75" :style="'width: '+ progress +'%'"></div>
        </div>
    </div>
</template>
<script>
export default {
    name: 'Slider',

    data: () => ({
        progress: 0,
        wrapperWidth: 0,
        seekOffsetLeft: 0,
    }),

    watch: {
        wrapperWidth() {
            this.seekOffsetLeft = 0
        },
    },

    mounted(){
        this.$refs.slider.addEventListener("click", this.getClickPosition, false)
        window.addEventListener('resize', e => this.wrapperWidth = this.$refs.slider.offsetWidth, false)
        this.$refs.slider.addEventListener("mousedown", this.detectMouseDown, false)
        this.$refs.slider.addEventListener("mousedown", this.detectMouseDown, false)
        document.addEventListener("mouseup", this.detectMouseUp, false)
    },

    methods: {
        getClickPosition(e) {
            if (e.target.nodeType === 3) e.target = e.target.parentNode // fix for a safari bug
            this.wrapperWidth = this.wrapperWidth || e.target.offsetWidth // set initial wrapper width
            let seekWidth = e.offsetX
            this.progress = (seekWidth / this.wrapperWidth) * 100
        },
        mouseMove(e) {
            if (e.target.nodeType === 3) e.target = e.target.parentNode // fix for a safari bug
            this.wrapperWidth = this.wrapperWidth || e.target.offsetWidth // set initial wrapper width
            if (!this.seekOffsetLeft) this.seekOffsetLeft = e.target.offsetLeft // set the offset left (document -> seek el left side)

            let x = e.pageX,
                seekRight = this.seekOffsetLeft + this.wrapperWidth,
                progress

            if (x < this.seekOffsetLeft) progress = 0
            else if (x > seekRight) progress = 100
            else progress = ((x - this.seekOffsetLeft) / this.wrapperWidth) * 100

            this.progress = progress
        },
        detectMouseDown(e) {
            e.preventDefault()
            document.addEventListener("mousemove", this.mouseMove, false)
        },
        detectMouseUp(e) {
            document.removeEventListener("mousemove", this.mouseMove, false)
        },
    },
}
</script>

The result should be obvious by reading the code it think, but still:

  • able to control the progress on mouse move event outside the wrapper div
  • going to the left of the wrapper div will result in setting progress to 0,
  • going to the right of it - set progress to 100
  • default - set progress 0-100

If you like the idea maybe you will add it to your component in some form or I can try to fit it into your component in a more consistent way and do a PR for it :) would be happy to contribute tiny little bit :)

BTW I'm also thinking of adding mouse wheel scroll event listener too..

Failed to mount component: template or render function not defined

Hey, I don't know if this is a dumb question but I tried using this component via npm install, but I get the error

webpack-internal:///./node_modules/vue/dist/vue.runtime.esm.js:620 [Vue warn]: Failed to mount component: template or render function not defined.

found in

---> <XnsSeekBar>
       <Footer> at src/components/Footer.vue
         <Player> at src/views/Player.vue
           <App> at src/App.vue
             <Root>

In Footer.vue (and main.js), I added - what am i doing wrong?

import XnsSeekBar from 'xns-seek-bar';
Vue.use(XnsSeekBar)
...
  components: {
   // ProgressBar,
    "xns-seek-bar": XnsSeekBar
    },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.