1.0.0 • Published 5 years ago

@eyelly/print v1.0.0

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

Print

Print is a simple function for partial printing on the browser

Installation

NPM

npm i -S @eyelly/print

CDN

<script src='https://unpkg.com/@eyelly/print/dist'></script>

Usage & Example

In Module

import print from '@eyelly/print'

const fooDom = document.getElementById('xxx')
print({
  content:fooDom
})

In HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <script src='https://unpkg.com/@eyelly/print/dist'></script>
  </head>

  <body>
    <div id='content'> this is content to print </div>
    <div> this is normal content </div>
    <button id='button1'>normal print</button>
    <button id='button2'>new window print</button>
    <script>
      const content = document.getElementById('content')
      const button1 = document.getElementById('button1')
      const button2 = document.getElementById('button2')

      button1.addEventListener('click', () => {
        print({
          content
        })
      })

      button2.addEventListener('click', () => {
        print({
          content,
          newWindow: true,
          title: 'print example'
        })
      })
    </script>
  </body>

</html>

API

PropertyDescriptionTypeDefault
contentcontent to be printedHTMLElement-
newWindowopen a new window to printbooleanfalse
titlethe title of the newly opened windowboolean-

License

MIT