[Sticky social media buttons floating on the side of a page]
I set this up for PRC, which is a Drupal 8 site. However, this would work in WordPress too.
How they look/act:
Things of note:
position: relative;
.container
so it matches the width & margins of the content.position: absolute;
and height: 100%;
. This makes the wrapper actually fill 100% of the height of the main content area, giving a "track" that the social media icons can slide around inside.{% if not homepage %}
{% include "@molecules/15-social-media/10-sharing-buttons/10-sharing-buttons.twig" with {
socialsharing_modifiers: ['sticky-left'],
facebook: true,
twitter: true,
sharethis: true
} only %}
{% endif %}
{% set wrapper_mods = '' %}
{% set mods = '' %}
{% for mod in socialsharing_modifiers %}
{% set mods = mods ~ " socialsharing--" ~ mod %}
{% endfor %}
<div class="socialsharing__wrapper">
<div class="socialsharing {{ mods }}">
{% if twitter %}
<div class="socialsharing__button st-custom-button" data-network="twitter">
<i class="icon icon-twitter" title="{{ 'Share on Twitter'|trans }}"></i>
</div>
{% endif %}
{% if facebook %}
<div class="socialsharing__button st-custom-button" data-network="facebook">
<i class="icon icon-facebook" title="{{ 'Share on Faceook'|trans }}"></i>
</div>
{% endif %}
{% if sharethis %}
<div class="socialsharing__button st-custom-button" data-network="sharethis">
<i class="icon icon-sharethis" title="{{ 'Share with ShareThis'|trans }}"></i>
</div>
{% endif %}
</div>
</div>
@import "../../../variables";
@import "../00-social-link/00-social-link";
.socialsharing__wrapper {
$socialsharing-breakpoint: 1020px;
$socialsharing-max-widths:
($breakpoint-sm: 540px,
$breakpoint-md: 720px,
$breakpoint-lg: 960px);
margin-right: auto;
margin-left: auto;
@include rem('padding-left', $gutter-width);
@include rem('padding-right', $gutter-width);
position: relative;
@each $breakpoint,
$max-width in $socialsharing-max-widths {
@include breakpoint($breakpoint) {
max-width: $max-width;
}
}
@include breakpoint($socialsharing-breakpoint) {
height: 100%;
margin: 0;
max-width: unset;
padding: 0;
position: absolute;
top: 0;
}
.socialsharing {
display: flex;
position: relative;
@include socialmedia(40px, 17px, $color--marine-blue, white, false);
@media (min-width: $socialsharing-breakpoint) {
display: block;
padding-bottom: 0;
padding-left: 0;
position: absolute;
@include rem('top', 100px);
}
&--sticky-left {
@include rem('padding-bottom', 20px);
@media (min-width: $socialsharing-breakpoint) {
position: sticky;
// 132px is the height of the header
top: calc(50% + 132px);
transform: translateY(-50%);
}
.socialsharing__button {
@media (min-width: $socialsharing-breakpoint) {
@include rem('margin-bottom', 7px);
}
}
}
}
.socialsharing__button {
cursor: pointer;
}
}