1.0.16 • Published 4 years ago

ellipsis-text v1.0.16

Weekly downloads
98
License
MIT
Repository
github
Last release
4 years ago

EllipsisText

A generator that gets the minimum content that corresponds to the height of an element

Installation

npm:

npm install ellipsis-text --save-dev

Demo

demo

Usage example

<div id="ellipsis" style="width:280px"></div>

string input

import EllipsisText from 'ellipsis-text'
new EllipsisText(document.querySelector('#ellipsis'), {
  str:
    'Fame,wealth and knowledge are merely worldly possessions that are withinthe reach of anybodyFame,wealth and knowledge are merely worldly possessions that are withinthe reach of anybodyFame',
  callback: function(res) {
    console.log(res)
    // output:Fame,wealth and knowledge are merely worldly possessions that are withinthe reach of anybodyFame,wealth and knowled
  }
})

you can use it to generate text with ellipsis

new EllipsisText(document.querySelector('#ellipsis'), {
  str:
    "You'll pass the churchyard, Mr Lockwood, on your way back to the Grange, and you'll see the three graverestones close to the moor. Catherine's",
  callback: function(res) {
    console.log(this.dotdotdot())
    // output:You'll pass the churchyard, Mr Lockwood, on your way back to the Grange, and you'll see the three grave...
  }
})

example

EllipsisText API

options

new EllipsisText(HTMLElement, {
  str: String,
  row: Number,
  scrollTop: Number,
  callback: function(res) {}
})

method

ellipsisText.reCompute(str,callback)

Recalculate and return the new result,this will save a lot of time than initialization

ellipsisText.dotdotdot(ellipsis = "...", str)

Tips

EllipsisText used canvas to determine the number of lines to be intercepted

If you pass in HTML, it deletes the nodes one by one to find the last text node that exceeds the height

function dotdotdot just replace last three letter, but you can use dotdotdot.js to do the following or rewrite this function

Performance

The following is an EllipsisText performance test (in ms)

npm.io

Development setup

npm install

npm run dev

npm run test

Release History

  • 1.0.0
    • The first release

Meta

Mater1996 – bxh8640@gmail.com

Distributed under the MIT license. See LICENSE for more information.

LICENSE

Contributing

  1. Fork it (https://github.com/Mater1996/ellipsis-text)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request
1.0.16

4 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago