npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@penglei188288/clampjs

v2.0.0

Published

文本超出省略、基于js的实现方式

Downloads

4

Readme

安装

npm install @penglei188288/clampjs --save
# or
yarn add @penglei188288/clampjs

示例

import { createClamp } from '@penglei188288/clampjs'

const example = createClamp(document.getElementById('app'), {
    clamp: 2,
    useNative: false,
    suffixHTML: '<span class="text-primary m-l-5">...查看全部</span>',
    responsive: false,
    suffixClick: (original) => {
        alert(original)
    }
})

example.reset() //刷新
example.destroy() // responsive为true时会监听resize事件,调用destroy()函数,会清除监听的事件。以免造成性能问题

参数

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ------------ | ------------ | ------------ | ------------ | ------------ | | clamp | 这个选项控制何时何地去限制文本元素。第一,当选项为数字的时候,则代表应该被显示的行数。第二,你可以使用代表 CSS的值(px,em)字符串来控制元素显示的高度。最后,你可以使用’auto’字符串。’auto’将会尝试铺满有效的空白区域并且自动的限制元素使其自适应。 | number/string | — | 2 | | useNative | 是否使用原生的 -webkit-line-clamp 属性在 支持的浏览器中。 默认是true 。如果你使用的是 Webkit 内核的浏览器,但是在某些情况下,显示不正常。你可以把这个值设置为false,使用基于js的实现方式 | boolean | true | false | | responsive | 是否监听窗口变化以触发刷新,useNative为true时不会监听。使用后注意调用实例的destroy ()函数销毁,以免出现性能问题 | boolean | true | false | | suffixHTML | 在HTML元素截断之后显示的字符串,默认是省略号(…)。同时支持 字符串和HTML标签。useNative为false时生效 | string | — | ... | | suffixClick | 点击省略号触发时的回调函数,回调的参数为original。useNative为false时生效 | Function(original) | — | — |

维护者

License