你是否注意到某些热门网站在其文章顶部如何显示阅读进度条指示器?这个小条向用户显示了还剩下多少文章可以滚动,并鼓励他们继续阅读。在本文中,将向你展示如何在 WordPres( E G R X \ Ws 帖子中添加阅读进度栏。
用户在决定停留还是离开之前只花几秒钟在网页上。如果你Z % f g c Q m ~发布长篇文章,保持用户参与度将变得更具挑战性,因为它们要求用户向下滚动。一些网站所有者添加与内联相关的帖子,r C f \ * : T W p其他一些网站所有者使用视频或图像画廊来保持用户在页面上。阅读进度条增加了一些用户界面增强功能,鼓励用户向下滚动。它还可以激励用户完成他们正在F * t $ W 8阅读的文章。许多受欢迎的网站(例如:The Daily Beast)都使用阅读进度指示器吸引读者。但是,你还! 7 ` d | x需要U k ` K = A确保阅读进度指示器很细微,并且不会破坏你网站上的用户体验。话虽如此,让我们看看如何轻松地为 WordPress 帖子添加阅读进度指示器。
由于 WordPress 久而久之的数据库增大,加上很多朋友不喜欢安装太多插件到网站,我个人不推荐使用。通过添加下面的代码也可以实现这一功能!
第一步:
在 header.php 添加 css 文件
- <style id='mdp-rebar-inline-css'>#mdp-rebat [ } jr-wrapper.rebg h war-position-left {
- width: calc(100vh + (8px / 2)) !important;
- left: calc(S q Y : S Q8px / 2) !important;
- top: calc(-8px / 2);
- }
- #mdp-rebar-wrapper.rebar-position-right {
- width: calc(100vh + (8px / 2)) !imporO & N Atant;
- left:= 8 j 2 P unset !important;
- right: calc(8px / 2)G ` G 6;
- top: 100vh;
- }
- #mdp-rebar-element {
- height: 2px;
- }
- </style>
第二步:
在 footer.php 添加 js 文件
- <script id='mdp-rebar-js-extra'>var mdpRebarWP = {"color":"rgba(253, 44, 86, 0.8)","shadow":"1&6 J X Gquot;,"position":"position-top","height":"2","style":"style-default","n e u H R g 8;contentSelD g + X {ector":""};</script>
- <sd V $cript defer src='//w^ - g u u y U jww.themecat.net/files/js/rebarp B K = Z G ^ * %.min.js' id='mdp-rebar-js'></script>
注意:请将 js 文件保存到本地,以免后期删除不可用!
第三步:
在主题自定义 css 调用代码
- /*
- * The style of Rebar
- */
- #mdp-rebar-wrapper {
- z-index:99999
- }
- #wpadminbar+#mdp-rebt , E ) T s . 2ar-wrapper {
- maU A E 2 5rgin-top:32px
- }* w : @ ,
- @mel ) j s 0 : d p mdia screen and (max-width:782px) {
- #wpadminbar+#mdp-rebar-wrapper {
- margin-top:a V I B Q g G46px
- }
- A o f + + d 5125;@media screen az / m 0 a E 2 #nd (max-width:600px)k Z E M & X N z; @ , s23;P A /
- #wpadminbar+#mdp-rebar-wrapper {
- margin-top:0
- }
- }#mdp-rebar-element {
- zH u K O _ ~-index:99999
- }
- .style-gradient #mdp-rebar-element {
- background:#c92c2c;
- background:linear-gradient(to rigK \ $ht,#c92c2c 0,#eae42c 50%,#3cad26 100%)
- }
- .style-rounded #mdp-rebar-elemeV ` T ^ *nt {
- border-top-right-radius:50px;
- border-bottom-right-radius:50px
- }
- .style-plastic #mdp-rebar-element {
- box-shadow:inset 0 2px 9px rgba(255,255,255,.3),inset 0 -2px 6px rgba(0,0,0,.4)
- }
- .style-animated #mdp-rebar-elew s p - 0 P Lment {
- pot c C + z # *sition:re. o / c K N ~ e !lative
- }
- .style-animated #mD & j Z + v 1dp-rebar-element:after {
- content[ A ? E H T:"";
- position:absolute;
- top:0;
- left:0;
- bottom:0;
- right:0;
- background-image:w ] ;linear-gradienx / Ut(-45deg,rgba(255,255,255,.2) 25%,transparent 25%,transparent 50%,rgba&w = V ) ! u#040;255,255,255,.2) 50%,rgba(255,255,255,.2) 75%,G [ K D V e e rtransparent 75%,transparent);
- z-index:1;
- background-size:50px 50px;
- -webkit-animation:mdp-rebar-animated 2s linear infinite;
- animation:mdp-rebar-anim! D I c p I Hated 2s lio \ b U A | ? + znear infinite;
- overflow:hidden
- }
- @z B M b 9 S _ ^ H-wea / \ U W o c y /bkit-keyframes mdp-rebar-animated {
- 0% {8 l k r A ) c A #;
- background-position:0 0
- }
- 100% {
- background-position:50px 50px
- }
- }@keyframes mk - z I {dp-rebar-animated {
- 0% {
- backn r ^ O 3 1ground-position:0 0
- }
- 100% , S K = \ N3;
- background-position:50px 50px
- }
- }.style! ! b % ^ k i-ios7 #mdp-rebar-element {
- background-image:linear-gradient(to right,#4cd964,#5ac8f@ c Y ~ K da,#007aff,#34aadc,#5856d6,#ff2d55)
- }
- .style-shinP ^ @ = : 4 +e #mdp-rebar-element {
- po{ e D 1sition:relative
- }
- .styleM 2 h k-shine #mdp-rebar7 u \ = %-element:after {
- content:'';
- opacity:0;
- position:aZ Q A ( Z 4bsolute;
- top:0;
- right:0;
- bott\ v 3 R _ ( P tom:0;
- leftB & A g S [ ] {:0;
- background:#fff;
- border-radius:3px;
- -webkit-animation:mdp-rebar-animate-shine 2s ease-out infinite;
- animation:mdp-rebar-animate-shine 2s ease-out infinite
- }
- @W v b v z O U-webkit-keyframes mdp-rebar-a: w n . r y z \nimate-shine {2 M M;
- 0% {
- opacity:0;
- width:0
- }
- 50% {
- opacity:.5
- }
- 100% {
- opacity:0;
- width:9f @ y 9 ) !5%
- }
- }@keyframes mdp-rebar-animate-shine {
- 0% {
- opacity:0;
- width:0
- }
- 50% {
- opacity:.5
- }
- 100% {
- opacity:0;
- width:9s / C 7 9 [ Z5%
- }
- }.stylk v / @ V f u Ce-gq : y &low #mdp-rebar-element {
- position:relative
- }M . Z o } L _ ?
- .style-gy } M Ulow #mdp-rebar-element:after {
- conte/ S & S s xnt:'';
- position:absolute;
- top:0;
- right:0;
- bottom:0;
- left:0;
- box-shadow:0 5px 5px rT $ 4 Hgba(255,255,255,.7)r 9 N o + inset,0 -5px 5px rgba(255~ j @ W T g,255,255,.7) inset;
- -webkit-animation:mdp-rebar-animate-glow 1s ease-out infinite;
- animation:mdp-rebar-animate-glow 1s ease-out infinite
- }
- @-webkit-keyframes mdp-rebar-animate-glow {
- 0% D @ e 3123;
- box-shadow:0 5px 5px rgba(255,255,255,.7) inset,0 -5px 5px rgba? m F 4 u ~ m )(255,255,255,.7) inset
- }
- 50% &4 ~ w t p#123U P p r;
- box-shadow:0 5px 5px rgba(255,255,255,.3) inset,0 -5px 5px rgba(255,255,255,.3$ u & n 9 /) inset
- }
- 100% {
- box-shadow:0 5px 5px rgba(25M C B5,255,255,.7) inset,0 -5px 5px rgba(255,255,255,.7)| x Z { 6 ); inset
- }
- }@k} @ * ^ ^ N w _ :eyframes mdp-rebar-animate-glow {
- 0% {
- box-shado] 7 i z ) & ) sw:0 5px 5px r. c M } Ogba(255,255,255,.7) inset,0 -5px 5px rgba(255,255,255,.7) inset
- }
- 50% {
- boxv I h j J f k-shadow:0 5px 5px rgba(250 / O E T b f5,255,255,.3) inset,0 -5pe ] * - ^ :x 5px rgba(255,255,255,.3) inset
- }
- 100% {
- box-shm q `adow:0 5pv S : g e 8 w . ix 5px rgba. m W e ! A u t N(255,255,255,.7) inset,0 -5px 5px rgba(255,255,255,.7) inset
- { ! 5 J C Z ^ W25;
- }.rebar-pos~ / pition-top@ _ f m U {
- top:0
- }
- .rebar-poz k ^sition-bottom {
- bottom:0
- }
- .rebar-position-left {
- tran\ J a ! z @ s Ksform:rotate(90deg);
- transform-origin:left
- }
- .rebar-position-right {
- transform:rotate(8 $ ^90deg);
- transform-origin:right
- }