{"id":26409825,"url":"https://github.com/patik/within-viewport","last_synced_at":"2025-10-06T11:16:00.228Z","repository":{"id":57398471,"uuid":"2586661","full_name":"patik/within-viewport","owner":"patik","description":"JavaScript utility that determines whether an element is completely within the browser viewport","archived":false,"fork":false,"pushed_at":"2024-09-18T02:30:58.000Z","size":1255,"stargazers_count":255,"open_issues_count":15,"forks_count":57,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-09-25T18:36:19.730Z","etag":null,"topics":["browser","javascript","viewport","viewport-dimensions"],"latest_commit_sha":null,"homepage":"http://patik.github.io/within-viewport/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-10-16T15:52:50.000Z","updated_at":"2025-08-01T06:07:57.000Z","dependencies_parsed_at":"2023-02-12T22:01:35.970Z","dependency_job_id":"e93fc70c-36c5-40aa-8ed6-46b60f55288c","html_url":"https://github.com/patik/within-viewport","commit_stats":{"total_commits":96,"total_committers":9,"mean_commits":"10.666666666666666","dds":"0.47916666666666663","last_synced_commit":"74348fe614dc9935230b8ee1cb442e78821463d1"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/patik/within-viewport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patik%2Fwithin-viewport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patik%2Fwithin-viewport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patik%2Fwithin-viewport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patik%2Fwithin-viewport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patik","download_url":"https://codeload.github.com/patik/within-viewport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patik%2Fwithin-viewport/sbom","scorecard":{"id":721966,"data":{"date":"2025-08-11","repo":{"name":"github.com/patik/within-viewport","commit":"7cf9687fe1dafa90a62fdb0d92244974fa03b773"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/6 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cypress.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/cypress.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/cypress.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/cypress.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/dependabot-auto-merge.yaml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/dependabot-auto-merge.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-static.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/github-pages-static.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-static.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/github-pages-static.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-static.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/github-pages-static.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-static.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/github-pages-static.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/linting-and-unit-tests.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/linting-and-unit-tests.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/linting-and-unit-tests.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/linting-and-unit-tests.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-npm-github-packages.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/patik/within-viewport/publish-npm-github-packages.yml/main?enable=pin","Info:   0 out of  13 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/publish-npm-github-packages.yml:26","Warn: jobLevel 'packages' permission set to 'write': .github/workflows/publish-npm-github-packages.yml:27","Info: jobLevel 'contents' permission set to 'read': .github/workflows/publish-npm-github-packages.yml:44","Warn: jobLevel 'packages' permission set to 'write': .github/workflows/publish-npm-github-packages.yml:45","Warn: no topLevel permission defined: .github/workflows/cypress.yml:1","Warn: topLevel 'contents' permission set to 'write': .github/workflows/dependabot-auto-merge.yaml:8","Info: topLevel 'contents' permission set to 'read': .github/workflows/github-pages-static.yml:13","Warn: no topLevel permission defined: .github/workflows/linting-and-unit-tests.yml:1","Warn: no topLevel permission defined: .github/workflows/publish-npm-github-packages.yml:1"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"12 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-xq7p-g2vc-g82p","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-x7hr-w5r2-h6wg","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T11:37:35.485Z","repository_id":57398471,"created_at":"2025-08-22T11:37:35.485Z","updated_at":"2025-08-22T11:37:35.485Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278599105,"owners_count":26013401,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["browser","javascript","viewport","viewport-dimensions"],"created_at":"2025-03-17T19:37:03.135Z","updated_at":"2025-10-06T11:16:00.210Z","avatar_url":"https://github.com/patik.png","language":"TypeScript","readme":"# Within Viewport\n\n***Determine whether elements are completely within the viewport***\n\nIncludes:\n\n- The synchronous function, `withinViewport()`\n  - Continues to support [legacy browsers](#browser-support)\n- The asynchronous, promise-based function, `withinViewportAsync()`\n  - More performant, but only for [modern browsers](https://caniuse.com/intersectionobserver) (e.g. post IE 11)\n- Optional jQuery plugin with handy selectors and shorthand methods\n- TypeScript support\n- Support for CommonJS and ESM modules\n\nAll of the above offer the same features.\n\n## Install\n\n```sh\nyarn add withinviewport\n```\n\nor\n\n```sh\nnpm install withinviewport\n```\n\nAnd then in your JavaScript or TypeScript:\n\n```js\nimport { withinViewport /* or withinViewportAsync */ } from 'withinviewport'\n```\n\nBoth CommonJS and ESM modules are provided.\n\n## Usage\n\n### Basic\n\n```js\n// Returns true if the element is entirely within view of the window\nconst elem = document.getElementById('#myElement')\n\nwithinViewport(elem) // returns a boolean\nwithinViewportAsync(elem) // returns a Promise\u003cboolean\u003e\n```\n\n### Advanced\n\nAll options work the same for both the synchronous and asynchronous functions.\n\n```js\n// Test against only some sides of the window for faster performance\nwithinViewport(elem, { left: 'ignore' })\n```\n\n```js\n// Pick another element to act as the viewport (instead of `window`)\nwithinViewport(elem, { container: document.getElementById('myElem') })\n```\n\n```js\n// Define your own viewport crop by specifying thresholds for each side\n// Example: element is at least 12px inside the top and right of the viewport\nwithinViewport(elem, { top: 12, right: 12 })\n```\n\nFor more options, see [Options](#options) section below.\n\n### Shorthand notation\n\n```js\n// This will only check the bottom and right of the viewport, ignoring the top and left\nwithinViewport(elem, 'bottom right')\nleft(elem)\n```\n\n## jQuery plugin\n\nBe sure to include the full version of the script as well\n\n```js\n\u003cscript src=\"withinviewport.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"jquery.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"jquery.withinviewport.js\"\u003e\u003c/script\u003e\n```\n\n### Basic usage\n\n```js\n// Returns true if the element is entirely within the viewport\n$('#myElement').is(':within-viewport')\n```\n\n```js\n// Returns a jQuery object of all \u003cdiv\u003es that are within the viewport\n$('div').withinViewport()\n```\n\n### Advanced usage\n\nThere are shorthand selectors and methods for testing against only one edge of the viewport.\n\n```js\n// Returns true if the element is within the left edge of the viewport\n// Also works with 'top', 'right', and 'bottom'\n$('#myElement').is(':within-viewport-left')\n```\n\n```js\n// Returns a jQuery collection of all \u003cdiv\u003es within the left edge of the viewport\n$('div').withinViewportLeft()\n```\n\n```js\n// Same as above, but only elements that are at least 12px inside the left edge\n$('div').withinViewportLeft({ left: 12 })\n```\n\nThese shortcuts will result in slightly better performance if you're testing hundreds or thousands of elements.\n\n#### Live updating\n\nIf you're looking to keep tabs on elements' whereabouts at all times, you can bind to the `window`'s `resize` and `scroll` events. However, for performance reasons, it's strongly recommended to [throttle](https://lodash.com/docs/#throttle) your event listener or use something like [James Padolsey's `scrollStop` event](https://web.archive.org/web/20210824132834/https://j11y.io/javascript/special-scroll-events-for-jquery/). Firing on every `window.scroll` event will [bring your UI to its knees](https://ejohn.org/blog/learning-from-twitter/).\n\n```js\n$(window).on('resize scrollStop', _.throttle(function() {\n    // Your code here...\n\n    // Example:\n    $('div')\n        // Momentarily declare all divs out of the viewport...\n        .removeClass('within-viewport')\n        // Then filter them to reveal which ones are still within it\n        .filter(':within-viewport')\n            .addClass('within-viewport')\n}, 100));\n```\n\n## Options\n\nAll options work the same across the synchronous and asynchronous functions and the jQuery plugin.\n\n### Custom viewport element\n\nIf you want to test whether an element is within a scrollable parent element (e.g. which has `overflow: auto` or `scroll`), assign the parent element to the `container` property:\n\n```js\nwithinViewport(elem, {\n    container: document.querySelector('.parent-element')\n})\n```\n\n### Custom boundaries\n\nFor example, a fixed header with a height of 100px that spans the entire width of the page effectively lowers the viewport by 100px from the top edge of the browser window:\n\n```js\nwithinViewport(elem, { top: 100 })\n```\n\nIf you only care about some edges of the viewport, you can specify them to improve performance:\n\n```js\nwithinViewport(elem, 'left bottom')\n```\n\nYou can also combine optins:\n\n```js\nwithinViewport(elem, { left: 40, container: myDiv })\n$('div').withinViewport({ right: -70, top: 'ignore' })\n```\n\nYou can specify *negative threshold values* to allow elements to reside outside the viewport.\n\n## Migrating from v2 to v3\n\nThe `sides` option has been deprecated. The following calls are equivalent:\n\n```js\n// 2.x: specifying which sides to *monitor*\nwithinViewport(elem, { sides: ['left', 'right']})\n\n// 3.x: specifying which sides to *ignore*\nwithinViewport(elem, { top: 'ignore', bottom: 'ignore' })\n```\n\n## Browser Support\n\nFor the synchronous functions:\n\n- IE 7(?) and higher\n- All the others except Opera Mini\n  - Tested in the latest stable Chrome, Firefox, Safari, and Edge\n\nThe asynchronous functions work in any browser that supports promises and [IntersectionObserver](https://caniuse.com/intersectionobserver).\n\nAll functions (both versions) are transpiled to ES5.\n\n## Credit\n\nWithin Viewport is inspired by these similar utilities which only reflect whether an element is at least partially in view:\n\n- Remy Sharp's [Element 'in view' Event Plugin](https://remysharp.com/2009/01/26/element-in-view-event-plugin/)\n- Mike Tuupola's [Viewport Selectors for jQuery](https://github.com/tuupola/jquery_viewport)\n\n## License\n\nHave fun with it \u0026mdash; [BSD-3-Clause](https://choosealicense.com/licenses/bsd-3-clause/). See included [LICENSE](LICENSE) file.\n\n## Author\n\n[Craig Patik](https://patik.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatik%2Fwithin-viewport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatik%2Fwithin-viewport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatik%2Fwithin-viewport/lists"}