{"id":25492232,"url":"https://github.com/athm-fe/sticky","last_synced_at":"2025-11-08T21:30:24.560Z","repository":{"id":57099851,"uuid":"129371764","full_name":"athm-fe/sticky","owner":"athm-fe","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-17T10:19:58.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-12T11:44:55.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://athm-fe.github.io/sticky/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athm-fe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-13T08:19:52.000Z","updated_at":"2018-04-17T10:19:47.000Z","dependencies_parsed_at":"2022-08-22T23:10:37.437Z","dependency_job_id":null,"html_url":"https://github.com/athm-fe/sticky","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athm-fe%2Fsticky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athm-fe%2Fsticky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athm-fe%2Fsticky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athm-fe%2Fsticky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athm-fe","download_url":"https://codeload.github.com/athm-fe/sticky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239561514,"owners_count":19659475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T22:29:11.143Z","updated_at":"2025-11-08T21:30:24.515Z","avatar_url":"https://github.com/athm-fe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sticky\n\n由于吸顶的实现采用的是 `position: fixed`，所以需要自己在样式里手动设置 `width` 。\n\n## Usage\n\n通过脚本来初始化，如果不配置参数，默认开启吸顶功能。\n\n```javascript\n$('.sticky-demo').sticky();\n```\n\n配置吸顶时到顶部的距离为 10px\n\n```javascript\n$('.sticky-demo').sticky({\n  offset: 10 // 开启吸顶，吸顶时到顶部距离为 10px\n});\n\n// or\n\n$('.sticky-demo').sticky({\n  offsetTop: 10 // 开启吸顶，吸顶时到顶部距离为 10px\n});\n```\n\n可以通过配置开启吸底效果\n\n```javascript\n$('.sticky-demo').sticky({\n  offsetBottom: 10 // 开启吸顶，吸顶时到顶部距离为 10px\n});\n```\n\n还可以通过 HTML data 属性的方式配置参数\n\n```html\n\u003cdiv class=\"sticky-demo\"\u003e\n  吸顶，到顶部距离为 0\n\u003c/div\u003e\n\u003cdiv class=\"sticky-demo\" data-offset=\"10\"\u003e\n  吸顶，到顶部距离为 10\n\u003c/div\u003e\n\u003cdiv class=\"sticky-demo\" data-offset-top=\"10\"\u003e\n  吸顶，到顶部距离为 10\n\u003c/div\u003e\n\u003cdiv class=\"sticky-demo\" data-offset-bottom=\"10\"\u003e\n  吸底，到底部距离为 10\n\u003c/div\u003e\n\u003cdiv class=\"sticky-demo\" data-offset-top=\"10\" data-offset-bottom=\"20\"\u003e\n  吸顶和吸底效果同时开启\n\u003c/div\u003e\n```\n\n## Options\n\n参数可以通过 data attributes 或者 JavaScript 两种方式来配置.\n\nName | Type | Default | Description\n---- | ---- | ------- | -----------\noffset | number or object | `{top:0}` | 用来设置吸顶和吸底的距离，格式 `{top: 10, bottom: 20}` ，其中 `top` 和 `bottom` 还可以是函数\noffsetTop | number or function | 无 | 设置吸顶距离\noffsetBottom | number or function | 无 | 设置吸底距离\n\n## Methods\n\n### `.sticky(options)`\n\n初始化\n\n```javascript\n$('#stickyDemo').sticky();\n```\n\n## Events\n\nEvent Type | Description\n---------- | -----------\ntop.fe.sticky | 进入吸顶状态时触发\nbottom.fe.sticky | 进入吸底状态时触发\noff.fe.sticky | 从吸顶或者吸底状态退出时触发\n\n```javascript\n$('.nav-example')\n  .on('top.fe.sticky', function() {\n    $(this).html('\u003cp\u003e吸顶状态\u003c/p\u003e')\n  })\n  .on('bottom.fe.sticky', function() {\n    $(this).html('\u003cp\u003e吸底状态\u003c/p\u003e')\n  })\n  .on('off.fe.sticky', function() {\n    $(this).html('\u003cp\u003e常规状态\u003c/p\u003e')\n  });\n```\n\n# End\n\nThanks to [Bootstrap](http://getbootstrap.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathm-fe%2Fsticky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathm-fe%2Fsticky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathm-fe%2Fsticky/lists"}