swup / fragment-plugin

A swup plugin for dynamically replacing containers based on rules 🧩
https://swup-fragment-plugin.netlify.app
MIT License
15 stars 1 forks source link

feat: new option `rule.scroll` #36

Closed hirasso closed 1 year ago

hirasso commented 1 year ago

Closes #34

Description

Adds a new rule option scroll, to overwrite the default behavior of disabling scroll.reset for fragment visits:

{
  scroll?: boolean | string;
}

Example1

Scroll to the top for a selected fragment visit:

const rules: FragmentRule[] = [
  {
    from: "/items/:filter?",
    to: "/items/:filter?",
    containers: ["#list"],
    scroll: true
  }
];

Example 2

Scroll to the element #list for a selected fragment visit:

const rules: FragmentRule[] = [
  {
    from: "/items/:filter?",
    to: "/items/:filter?",
    containers: ["#list"],
    scroll: '#list'
  }
];

Checks

daun commented 1 year ago

Sweet!