Last active
April 4, 2020 01:13
-
-
Save jamesozzie/c7a821ddc84425e99347841309aeb299 to your computer and use it in GitHub Desktop.
Back to top WordPress AMP plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
scroll-behavior: smooth; | |
} | |
body { | |
position: relative; | |
} | |
.scrolltop-wrap { | |
box-sizing: border-box; | |
position: absolute; | |
top: 12rem; | |
right: 2rem; | |
bottom: 0; | |
pointer-events: none; | |
-webkit-backface-visibility: hidden; | |
backface-visibility: hidden; | |
} | |
@supports (-moz-appearance: meterbar) { | |
.scrolltop-wrap { | |
clip: rect(0, 3rem, auto, 0); | |
} | |
} | |
.scrolltop-wrap a { | |
position: fixed; | |
position: -webkit-sticky; | |
position: sticky; | |
top: -5rem; | |
width: 3rem; | |
height: 3rem; | |
margin-bottom: -5rem; | |
-webkit-transform: translateY(100vh); | |
transform: translateY(100vh); | |
-webkit-backface-visibility: hidden; | |
backface-visibility: hidden; | |
display: inline-block; | |
text-decoration: none; | |
-webkit-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
pointer-events: all; | |
outline: none; | |
overflow: hidden; | |
} | |
.scrolltop-wrap a svg { | |
display: block; | |
width: 100%; | |
height: 100%; | |
} | |
.scrolltop-wrap a svg path { | |
-webkit-transition: all 0.1s; | |
transition: all 0.1s; | |
} | |
.scrolltop-wrap a #scrolltop-arrow { | |
-webkit-transform: scale(0.66); | |
transform: scale(0.66); | |
-webkit-transform-origin: center; | |
transform-origin: center; | |
} | |
@media print { | |
.scrolltop-wrap { | |
display: none !important; | |
} | |
} | |
html { | |
overflow-y: scroll; | |
overflow-x: hidden; | |
} | |
.scrolltop-wrap a svg path{ | |
fill: #21759b ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Back to Top & AMP - jamesozz.ie | |
* Plugin URI: http://www.jamesozz.ie | |
* Description: Back to top button. JavaScript free & AMP compatible | |
* Version: 1.0 | |
* Author: James Osborne | |
* Author URI: http://www.jamesozz.ie | |
*/ | |
add_action('wp_footer', function(){ | |
echo ' | |
<div class="scrolltop-wrap"> | |
<a href="#" role="button" aria-label="Scroll to top"> | |
<svg viewBox="0 0 612 612" style="enable-background:new 0 0 612 612;" > | |
<path d="M256,0C114.833,0,0,114.833,0,256s114.833,256,256,256s256-114.833,256-256S397.167,0,256,0z M383.188,302.75 | |
c-1.646,3.979-5.542,6.583-9.854,6.583h-32c-2.833,0-5.542-1.125-7.542-3.125L256,228.417l-77.792,77.792 | |
c-2,2-4.708,3.125-7.542,3.125h-32c-4.313,0-8.208-2.604-9.854-6.583c-1.604-3.979-0.729-8.583,2.313-11.625l117.333-117.333 | |
c4.167-4.167,10.917-4.167,15.083,0l117.333,117.333c2.042,2.042,3.125,4.771,3.125,7.542 | |
C384,300.042,383.729,301.438,383.188,302.75z"/> | |
</svg> | |
</a> | |
</div> | |
' | |
; }); | |
function wpse_load_plugin_css() { | |
$plugin_url = plugin_dir_url( __FILE__ ); | |
wp_enqueue_style( 'style1', $plugin_url . 'backtotop.css' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'wpse_load_plugin_css' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment