{"id":18774731,"url":"https://github.com/sztheory/turbolinks-scroll","last_synced_at":"2025-10-26T14:15:22.506Z","repository":{"id":35162055,"uuid":"214744304","full_name":"szTheory/turbolinks-scroll","owner":"szTheory","description":"Persist scroll position between Turbolinks AJAX calls","archived":false,"fork":false,"pushed_at":"2023-01-04T22:36:39.000Z","size":277,"stargazers_count":4,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T23:36:14.339Z","etag":null,"topics":["ajax","node","npm","position","rails","rails-ujs","scroll","stimulus","turbolinks","ujs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/turbolinks-scroll","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/szTheory.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}},"created_at":"2019-10-13T01:49:20.000Z","updated_at":"2022-02-11T15:41:58.000Z","dependencies_parsed_at":"2023-01-15T15:01:52.270Z","dependency_job_id":null,"html_url":"https://github.com/szTheory/turbolinks-scroll","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fturbolinks-scroll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fturbolinks-scroll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fturbolinks-scroll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fturbolinks-scroll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szTheory","download_url":"https://codeload.github.com/szTheory/turbolinks-scroll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689382,"owners_count":21145923,"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":["ajax","node","npm","position","rails","rails-ujs","scroll","stimulus","turbolinks","ujs"],"created_at":"2024-11-07T19:39:12.263Z","updated_at":"2025-10-26T14:15:17.486Z","avatar_url":"https://github.com/szTheory.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# turbolinks-scroll\n[![npm version](https://badge.fury.io/js/turbolinks-scroll.svg)](https://badge.fury.io/js/turbolinks-scroll) ![npm size](https://img.badgesize.io/szTheory/turbolinks-scroll/master/lib/scroll.js) ![npm size](https://img.badgesize.io/szTheory/turbolinks-scroll/master/lib/scroll.js?compression=gzip) [![Build Status](https://travis-ci.org/szTheory/turbolinks-scroll.svg?branch=master)](https://travis-ci.org/szTheory/turbolinks-scroll) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) [![npm](https://img.shields.io/npm/dt/turbolinks-scroll)](https://www.npmjs.com/package/turbolinks-scroll) ![GitHub stars](https://img.shields.io/github/stars/szTheory/turbolinks-scroll?style=social)\n\nPersist scroll position between Turbolinks AJAX calls. Based on code from [\"How To: Turbolinks 5 Scroll Position Persistence\"](https://medium.com/@kosovacsedad/how-to-turbolinks-5-scroll-position-persistence-6e4435a60b2e) by Sedad Kosovac\n\n## Setup\n\n```Javascript\nimport { turbolinksScrollSetup } from \"turbolinks-scroll\"\n\n// automatically persist scroll on click or submit\n// for any DOM element with data-turbolinks-scroll=false\nturbolinksScrollSetup(document)\n```\n\n## Usage\n\n#### DOM elements\n\nSet `data-turbolinks-scroll=false` DOM elements you want to persist scroll position for on their `click` or `submit` event\n\n```erb\n\u003c%= form_with model: @user, url: users_path, data: { 'turbolinks-scroll': false }  do |f| %\u003e\n\u003c% end %\u003e\n\n\u003c%= link_to 'Users', users_path, 'data-turbolinks-scroll': false  %\u003e\n```\n\n#### AJAX calls\n\n```JavaScript\nimport { turbolinksPersistScrollForNextVisit } from \"turbolinks-scroll\"\n\n// mark the next turbolinks visit to restore scroll position on load\nturbolinksPersistScrollForNextVisit()\n\n$.ajax({\n  type: 'PUT',\n  url: updateUrl,\n  data: {\n    id: id,\n    position: newPosition\n  },\n  success: function (resp) {\n  },\n  error: function () {\n  }\n})\n```\n\n#### Delegating to other events\n\n```JavaScript\nimport { turbolinksScrollSetTop } from \"turbolinks-scroll\"\n\n// mark the next turbolinks visit for scroll persistence when `myEvent` is triggered\ndelegate(\"[data-turbolinks-scroll]\", \"myEvent\", function (e) {\n  turbolinksPersistScrollForNextVisit()\n}, false)\n```\n\nNote the delegate call above uses the [delegate](https://www.npmjs.com/package/delegate) NPM module, which turbolinks-scroll depends on. You could do the same with jQuery like so:\n\n```js\n$(document).on(\"[data-turbolinks-scroll]\", \"myEvent\", function (e) {\n  turbolinksPersistScrollForNextVisit()\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsztheory%2Fturbolinks-scroll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsztheory%2Fturbolinks-scroll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsztheory%2Fturbolinks-scroll/lists"}