mirror of
https://github.com/bigskysoftware/htmx.git
synced 2026-01-25 05:06:13 +00:00
scroll fixes
This commit is contained in:
19
src/htmx.js
19
src/htmx.js
@@ -1963,7 +1963,7 @@ return (function () {
|
||||
if (modifier.indexOf("show:") === 0) {
|
||||
var showSpec = modifier.substr(5);
|
||||
var splitSpec = showSpec.split(":");
|
||||
var showVal = showSpec.pop();
|
||||
var showVal = splitSpec.pop();
|
||||
var selectorVal = splitSpec.length > 0 ? splitSpec.join(":") : null;
|
||||
swapSpec["show"] = showVal;
|
||||
swapSpec["showTarget"] = selectorVal;
|
||||
@@ -2014,18 +2014,13 @@ return (function () {
|
||||
}
|
||||
}
|
||||
if (swapSpec.show) {
|
||||
if (swapSpec.scrollTarget) {
|
||||
if (swapSpec.scrollTarget === "window") {
|
||||
if (swapSpec.show === "top") {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
if (swapSpec.show === "bottom") {
|
||||
window.scrollTo(0,document.body.scrollHeight);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
target = querySelectorExt(first, swapSpec.scrollTarget);
|
||||
var target = null;
|
||||
if (swapSpec.showTarget) {
|
||||
var targetStr = swapSpec.showTarget;
|
||||
if (swapSpec.showTarget === "window") {
|
||||
targetStr = "body";
|
||||
}
|
||||
target = querySelectorExt(first, targetStr);
|
||||
}
|
||||
if (swapSpec.show === "top" && (first || target)) {
|
||||
target = target || first;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<button hx-get="/demo" hx-swap="innerHTML show:window:bottom">Scroll Bottom Of Window</button>
|
||||
<hr/>
|
||||
<h3>Start</h3>
|
||||
<div id="scroll-target" style="height: 1500px; background-color: red; border: 1px solid black">
|
||||
<div id="scroll-target" style="height: 1500px; background-color: red; border: 1px solid black; scroll-margin:10px">
|
||||
<h1>Scroll Target</h1>
|
||||
</div>
|
||||
<button hx-get="/demo" hx-swap="innerHTML show:#scroll-target:top">Scroll Top Of Div</button>
|
||||
|
||||
Reference in New Issue
Block a user