I have the following script.
<script type="text/javascript">
$(function () { // document ready
var contentTop = $('.share').offset().top; // returns number
$(window).scroll(function () { // scroll event
var wayPoint = $(window).scrollTop(); // returns number
if (contentTop < wayPoint) {
var shareWidth = $('.content').width();
$('.share-active').width(shareWidth);
$('.share').replaceWith('<div class="share-active">SOCIAL BUTTONS</div>');
} else {
$('.share-active').replaceWith('<div class="share"></div>');
}
});
});
</script>
DEMO : http://jsfiddle.net/franciscop/b39M4/3/
Somehow the share-activediv is appearing before the scroll top reaches share div. I don't know what I am going wrong.
Also, anyway to animate the apperance of the share-active div so users are attracted to it.
Can you help me find where the problem is?