Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议增加右侧栏可以随屏滚动功能 #324

Closed
niux45 opened this issue Jan 16, 2021 · 6 comments
Closed

建议增加右侧栏可以随屏滚动功能 #324

niux45 opened this issue Jan 16, 2021 · 6 comments

Comments

@niux45
Copy link

niux45 commented Jan 16, 2021

现在很多主题都可以让右侧栏随着屏幕滚动,这样就可以让右侧一些重要的东西始终能让读者看到,希望能增加这个实用的功能

@seatonjiang
Copy link
Owner

这个之前版本有,后来因为兼容问题给下掉了,过年研究一下

@cyfrit
Copy link

cyfrit commented Feb 25, 2021

https://imold.wang/wordpress/153.html
我用没有问题

@Jomixedyu
Copy link

附议

seatonjiang added a commit that referenced this issue May 18, 2021
@seatonjiang
Copy link
Owner

新版本已经加上这个功能了,等推送更新即可。

@n0099
Copy link
Contributor

n0099 commented Jun 24, 2021

纯css能够实现sticky就请尽量不要引入外部js库

div.sidebar {
    display: block !important; #这行不必要因为我是在子主题中声明才需要这样覆盖的
    position: sticky;
    height: 100%;
    top: 36px;
}

@n0099
Copy link
Contributor

n0099 commented Jun 24, 2021

1.theia-sticky-sidebar这个库是在dom、document的scroll和resize事件(甚至没有做throttle/debounce,也就是会以超高频率(pc 30/60fps,移动端更高)触发该事件)中计算dom离viewport top的距离并不断位移dom位置来实现sticky效果的:https://github.com/WeCodePixels/theia-sticky-sidebar/blob/584d858b9a5203a9c1f3fd024be510436cfa3e62/js/theia-sticky-sidebar.js#L185-L256
2.并在https://github.com/WeCodePixels/theia-sticky-sidebar/blob/584d858b9a5203a9c1f3fd024be510436cfa3e62/js/theia-sticky-sidebar.js#L262-L297 中兼容了非默认position: static(使用相对绝对坐标定位)的dom
3.还额外使用了库css-element-queries及其附带的ResizeSensor.js(现在您可以使用ResizeObserver
https://github.com/WeCodePixels/theia-sticky-sidebar/blob/master/js/theia-sticky-sidebar.js#L294
https://github.com/WeCodePixels/theia-sticky-sidebar/blob/master/js/theia-sticky-sidebar.js#L319-L325

Theia Sticky Sidebar uses the CSS Element Queries library to detect when your sidebars change height, so that it can recalculate their positions. This can happen if you are using an accordion, for example.
You can choose not to include the ResizeSensor.min.js script in your page, in which case Theia Sticky Sidebar will continue to function (possibly even a bit smoother) but will not automatically detect height changes.

8af851f 中并没有引入ResizeSensor.js)

考虑到这个库最早写于2013年(js最后更新于17年),并且其主要是用于付费wp插件(卖$19)使用的,这些兼容性考虑并不奇怪,但已经不再适用于当今互联网环境,根据caniuse数据,2017年后发布的所有主流浏览器(safari 14年就支持)都支持position: sticky
除了必须要兼容IE11用户外,我想不出为何需要在2021年的今天引入一个写于8年前,性能欠佳,大小5.4KB(未gzip)的jquery api库来实现本功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants