Giter Site home page Giter Site logo

aintelligen / ellipsis.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from glinford/ellipsis.js

0.0 1.0 0.0 42 KB

Ellipsis.js - Pure Javascript Library to handle complex multilines ellipsis

Home Page: https://glinford.github.io/ellipsis.js/

License: MIT License

JavaScript 73.85% HTML 26.15%

ellipsis.js's Introduction

Ellipsis.js

Ellipsis.js is a Pure Javascript Library to add some ellipsis on some complex DOM elements such as multiline divs or elements with childs (links, spans, etc.). The library is fully responsive, works across all major browsers, and try to be highly configurable. It is also very light, with a size of ~4kb when minified.


Demo:

https://glinford.github.io/ellipsis.js/


Installation:

Bower

bower install ellipsis.js

NPM

npm install ellipsis.js

Or…

git clone https://github.com/glinford/ellipsis.js

Usage:

<script src="/your/path/ellipsis.min.js"></script>
<script type="text/javascript">
  Ellipsis(); //default conf
</script>

By default Ellipsis.js will work on DOM elements that have a 'clamp' class and will add ellipsis after 2 lines.


Configuration properties:

{
  ellipsis: '…', //default ellipsis value
  debounce: 0, //if you want to chill out your memory usage on resizing
  responsive: true, //if you want the ellipsis to move with the window resizing
  className: '.clamp', //default class to apply the ellipsis
  lines: 2 //default number of lines when the ellipsis will appear
  portrait: null //default no change, put a number of lines if you want a different number of lines in portrait mode,
  break_word: true //default the ellipsis can truncate words
}

Lists:

  • debounce | Number | Default: 0 | Value in Milliseconds. If set to 0, it will use window.requestAnimationFrame (or a polyfill for IE <= 9) to debounce the resize events.
  • responsive | Boolean | Default: true | True is you want the ellipsis to be responsive, false if not.
  • className | String | Default: '.clamp' | A class or valid query selector where you want your ellipsis to appear
  • lines | Number | Default: 2 | The maximum number of lines before ellipsis
  • portrait | Number | Default: null | If you want a different number from the lines property on portrait mode.
  • break_word | Boolean | Default: true | If true the words can be truncated by the ellipsis, eg: "Hello Wo…", if false they won't, eg "Hello …"

"Manual" mode:

You can use the Ellipsis.js object to apply the configuration to additional DOM elements after it has been loaded:

var ellipsis = Ellipsis();
var elements = document.getElementsByClassName('.special-title');
ellipsis.add(elements);

This can be done with a single element:

ellipsis.add(elements[0]);

If using Ellipsis.js manually, you can disable the selector option in the configuration like this:

var ellipsisConf = {className: false};
var ellipsis = Ellipsis(ellipsisConf);

Known Issues:

By default the line-height property of a text is 'normal' which cannot be computed with getComputedStyle() method. If that occurs we will replace the line-height from normal to font-size + 2px which is the default value for most of browsers/OS.

The library does some heavy computation so it wont be suitable for pages that have like 100 elements with 100 lines each. I will work on optimization in future releases.

SVG text not supported.


To Do / Contributions:

  • Speed Improvement
  • SVG text support
  • Gradient instead of "String" Ellipsis

Feel free to branch and PR :)


ellipsis.js's People

Contributors

glinford avatar btnwtn avatar yoranbrondsema avatar eccyan avatar migl avatar

Watchers

James Cloos avatar

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.