I need to keep my social buttons fixed in position on my website, even when the user scrolls down. I want them to be vertically centered on the right side like shown here:
https://i.sstatic.net/0xfSC.png
This is how my code is currently set up:
// Animate the element's value from x to y:
$({ someValue: 0 }).animate({ someValue: Math.floor(Math.random() * 3000) }, {
duration: 3000,
easing: 'swing', // can be anything
step: function () { // called on every step
// Update the element's text with rounded-up value:
$('.count').text(commaSeparateNumber(Math.round(this.someValue)));
}
});
function commaSeparateNumber(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
return val;
}
@import url("http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css");
body { margin-top:20px; }
.fa { font-size: 50px;text-align: right;position: absolute;top: 7px;right: 27px;outline: none; }
a { transition: all .3s ease;-webkit-transition: all .3s ease;-moz-transition: all .3s ease;-o-transition: all .3s ease; }
/* Visitor */
a.visitor i,.visitor h4.list-group-item-heading { color:#E48A07; }
a.visitor:hover { background-color:#E48A07; }
a.visitor:hover * { color:#FFF; }
/* Facebook */
a.facebook-like i,.facebook-like h4.list-group-item-heading { color:#3b5998; }
a.facebook-like:hover { background-color:#3b5998; }
a.facebook-like:hover * { color:#FFF; }
/* Twitter */
a.twitter i,.twitter h4.list-group-item-heading { color:#00acee; }
a.twitter:hover { background-color:#00acee; }
a.twitter:hover * { color:#FFF; }
/* Youtube */
a.youtube i,.youtube h4.list-group-item-heading { color:#c4302b; }
a.youtube:hover { background-color:#c4302b; }
a.youtube:hover * { color:#FFF; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="list-group">
<a href="#" class="list-group-item visitor">
<h3 class="pull-right">
<i class="fa fa-eye"></i>
</h3>
<h4 class="list-group-item-heading count">
1000</h4>
<p class="list-group-item-text">
Website Views</p>
</a><a href="#" class="list-group-item facebook-like">
<h3 class="pull-right">
<i class="fa fa-facebook-square"></i>
</h3>
<h4 class="list-group-item-heading count">
1000</h4>
<p class="list-group-item-text">
Facebook Likes</p>
</a><a href="#" class="list-group-item twitter">
<h3 class="pull-right">
<i class="fa fa-twitter-square"></i>
</h3>
<h4 class="list-group-item-heading count">
1000</h4>
<p class="list-group-item-text">
Twitter Followers</p>
</a><a href="#" class="list-group-item youtube">
<h3 class="pull-right">
<i class="fa fa-youtube-play"></i>
</h3>
<h4 class="list-group-item-heading count">
1000</h4>
<p class="list-group-item-text">
Youtube Subscribers</p>
</a>
</div>
</div>
</div>
</div>
My issue was trying to position this
position: fixed; right: 0; top: 100px;
above the <div class="container">
. The icons moved but the view rectangles stayed put.
When I placed the
position: fixed; right: 0; top: 100px;
below the <div class="list-group">
, it looked cramped and squeezed.