0.1.3 • Published 5 years ago

scarlet-reader v0.1.3

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Scarlet Reader

Scarlet reader is a picture/manga viewer based on Vue.

demos

demo src/examples gives more demos

features

  • horizon & vertical scrolling direction
  • normal & virtual scroller
  • sliding animation
  • touch event (only tested on Chrome mobile)
  • prev page/next page
  • slide to(only normal scroller)
  • slots for items

usage

npm install scarlet-reader

or

yarn add scarlet-reader

in main.js (or other place before using <ReaderSlider> tags)

import Vue from 'vue'

// some other code...

import Reader from 'scarlet-reader'

// register reader components
Vue.use(Reader)

// other code...
// new Vue()

In *.vue where you use it

<ReaderSlider :options="options" :items="items">
  <template v-slot:item="{ item, index, active }">
    <ReaderItem :index="index" :active="active">
      <img :src="item.src"/>
      <p>index: {{ index }}</p>
    </ReaderItem>
  </template>
  <template v-slot:pagination="{ item, current, total }">
    <ReaderPagination :current="current" :total="total">
      <div> {{ current + '/' + total }} </div>
    </ReaderPagination>
  </template>
</ReaderSlider>

and provide items and options in data

export default {
  
  // some code here...

  data () {
    const items = []
    for (let i = 1; i <= 1207; i++) {
      items.push({ src: `/static/${i}.jpg` })
    }
    return {
      items,
      options: {
        // some options
      }
    }
  }

  // other code...
}

items in the list can be customized in <ReaderItem> as the way you like

to-do list

  • support slideTo on virtual scroller
  • support current in options indicates to sliding to where after initialization
  • loading slot in <ReaderItem>
  • pagination
  • touch support on Safari
  • performance improvement

options

propertytypedefaultdescription
animateDurationNumber1000the duration of sliding animation
batchNumber16the amount of unreached items but pre-load into DOM
currentNumber0TO BE SUPPORTED slide to the item which has this index after initialization
directionStringverticalthe sliding direction
easingString, String'Quintic', 'Out'easing type of tween.js which controls sliding animation
heightString600pxheight of visible reader div percentage also supported (100%)
inertiaBooleantrueenable sliding animation
loadingBooleantrueTO BE SUPPORTED enable loading slot display
marginString0pxmargin between adjacent two items
paginationBooleantrueTO BE SUPPORTED enable pagination display
scaleString80%how much item will occupy on fixed direction center automatically
speedLimit{ down: Number, up: Number }{ down: 0.1, up: 10 }sliding speed greater than up will be limited to up during animation; speed less than down won't have inertia animation
virtualBooleantrueenable virtual scroller - less memory and time to load, but cannot use slideTo method
widthString400pxwidth of visible reader div percentage also supported (100%)

apis

<ReaderSlider>

props

  • options
    • type Object
    • example
      {
        virtual: true,
        direction: 'vertical',
        margin: '0px',
        width: '590px',
        height: '940px',
        inertia: true,
        loading: true,
        batch: 10,
        speedLimit: { down: 0.2, up: 8 }
      }
  • items
    • type Array
    • example
      [
        { src: '1.jpg' },
        { src: '2.jpg' },
        { src: '3.jpg' },
        { src: '4.jpg' },
        { src: '5.jpg' }
      ]

methods

  • slideTo
    slide to the given index. NOTE: ONLY support normal scroller, when options.virtual set to be false
  • prev
    slide to previous page
    • param void
    • returns void

example:

<!--in vue template-->
<ReaderSlider ref="slider" :options="options" :items="items">
  <!--ReaderItem-->
</ReaderSlider>
// in component
this.$refs.slider.slideTo(1)

events

  • changed
    current page has been changed for any reasons
    • param index
      new page index
  • prev
    trigger as prev method was invoked
    • param latest
      current page index (before change)
    • param next
      new page index (after change)
  • next
    trigger as next method was invoked
    • param latest
      current page index (before change)
    • param next
      new page index (after change)
  • slide-to
    trigger as slideTo method was invoked
    • param latest
      current page index (before change)
    • param next
      new page index (after change)

slots

  • item
    • scoped varibles
      • index Number current page index
      • item Object current page data
      • active Boolean whether this page is loaded to DOM
  • pagination
    • scoped varibles
      • item Object current page data
      • current Number current page index
      • total Number amount of items

<ReaderItem>

slots

license

MIT

about Scarlet

Scarlet is a cross-platform manga reader constructed by electron. One of components works with scarlet reader.