You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # dom-align
  2. ---
  3. align source html element with target html element flexibly.
  4. [![NPM version][npm-image]][npm-url]
  5. [![build status][travis-image]][travis-url]
  6. [![Test coverage][coveralls-image]][coveralls-url]
  7. [![gemnasium deps][gemnasium-image]][gemnasium-url]
  8. [![npm download][download-image]][download-url]
  9. [npm-image]: http://img.shields.io/npm/v/dom-align.svg?style=flat-square
  10. [npm-url]: http://npmjs.org/package/dom-align
  11. [travis-image]: https://img.shields.io/travis/yiminghe/dom-align.svg?style=flat-square
  12. [travis-url]: https://travis-ci.org/yiminghe/dom-align
  13. [coveralls-image]: https://img.shields.io/coveralls/yiminghe/dom-align.svg?style=flat-square
  14. [coveralls-url]: https://coveralls.io/r/yiminghe/dom-align?branch=master
  15. [gemnasium-image]: http://img.shields.io/gemnasium/yiminghe/dom-align.svg?style=flat-square
  16. [gemnasium-url]: https://gemnasium.com/yiminghe/dom-align
  17. [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
  18. [node-url]: http://nodejs.org/download/
  19. [download-image]: https://img.shields.io/npm/dm/dom-align.svg?style=flat-square
  20. [download-url]: https://npmjs.org/package/dom-align
  21. ## Screenshot
  22. <img height=444 src="http://gtms02.alicdn.com/tps/i2/TB1XIp2HXXXXXajaXXXgJfr8XXX-548-888.png">
  23. ## Install
  24. [![dom-align](https://nodei.co/npm/dom-align.png)](https://npmjs.org/package/dom-align)
  25. ## Feature
  26. * support IE9+ chrome firefox
  27. * support align points and offset
  28. * support auto adjust according to visible area
  29. ## Online Demo
  30. * http://yiminghe.github.io/dom-align/
  31. ## Usage
  32. ```js
  33. import domAlign from 'dom-align';
  34. // use domAlign
  35. // sourceNode's initial style should be position:absolute;left:-9999px;top:-9999px;
  36. const alignConfig = {
  37. points: ['tl', 'tr'], // align top left point of sourceNode with top right point of targetNode
  38. offset: [10, 20], // the offset sourceNode by 10px in x and 20px in y,
  39. targetOffset: ['30%','40%'], // the offset targetNode by 30% of targetNode width in x and 40% of targetNode height in y,
  40. overflow: { adjustX: true, adjustY: true }, // auto adjust position when sourceNode is overflowed
  41. };
  42. domAlign(sourceNode, targetNode, alignConfig);
  43. ```
  44. ## API
  45. ### void domAlign(source: HTMLElement, target: HTMLElement, alignConfig: Object):Function
  46. #### alignConfig object details
  47. <table class="table table-bordered table-striped">
  48. <thead>
  49. <tr>
  50. <th style="width: 100px;">name</th>
  51. <th style="width: 50px;">type</th>
  52. <th>description</th>
  53. </tr>
  54. </thead>
  55. <tbody>
  56. <tr>
  57. <td>points</td>
  58. <td>String[2]</td>
  59. <td>move point of source node to align with point of target node, such as ['tr','cc'],
  60. align top right point of source node with center point of target node.
  61. point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right)
  62. </td>
  63. </tr>
  64. <tr>
  65. <td>offset</td>
  66. <td>Number[2]</td>
  67. <td>offset source node by offset[0] in x and offset[1] in y.
  68. If offset contains percentage string value, it is relative to sourceNode region.</td>
  69. </tr>
  70. <tr>
  71. <td>targetOffset</td>
  72. <td>Number[2]</td>
  73. <td>offset target node by offset[0] in x and offset[1] in y.
  74. If targetOffset contains percentage string value, it is relative to targetNode region.</td>
  75. </tr>
  76. <tr>
  77. <td>overflow</td>
  78. <td>Object: `{ adjustX: boolean, adjustY: boolean, alwaysByViewport:boolean }`</td>
  79. <td>
  80. if adjustX field is true, then will adjust source node in x direction if source node is invisible.
  81. if adjustY field is true, then will adjust source node in y direction if source node is invisible.
  82. if alwaysByViewport is true, the it will adjust if node is not inside viewport
  83. </td>
  84. </tr>
  85. <tr>
  86. <td>useCssRight</td>
  87. <td>Boolean</td>
  88. <td>whether use css right instead of left to position</td>
  89. </tr>
  90. <tr>
  91. <td>useCssBottom</td>
  92. <td>Boolean</td>
  93. <td>whether use css bottom instead of top to position</td>
  94. </tr>
  95. <tr>
  96. <td>useCssTransform</td>
  97. <td>Boolean</td>
  98. <td>whether use css transform instead of left/top/right/bottom to position if browser supports.
  99. Defaults to false.</td>
  100. </tr>
  101. </tbody>
  102. </table>
  103. ## Development
  104. ```
  105. npm install
  106. npm start
  107. ```
  108. ## Example
  109. http://localhost:8020/examples/
  110. ## Test Case
  111. ```
  112. npm test
  113. npm run chrome-test
  114. ```
  115. ## Coverage
  116. ```
  117. npm run coverage
  118. ```
  119. open coverage/ dir
  120. ## License
  121. dom-align is released under the MIT license.