I have a fixed position element on a page. I want that element contained within a certain div tag of an ID or Class that I assign. Here is a fiddle with an example. In the example the floating bar should not go above or below the black box.
I do not mind using jQuery to change the functions, I am using v. 1.8.3.
Here as a site that shows an example of what I am after. Look on the left side.
Here is the code for the example:
HTML
<div class="wrapper">
<div class="top">
<p> </p>
</div>
<div class="container">
<p>Floating Bar Should not go above this point.</p>
<p> </p>
</div>
<p>Floating Bar Should not go below this point.</p>
<p> </p>
</div>
<div class="add-this-container" >
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_floating_style addthis_counter_style">
<a class="addthis_button_facebook_like" fb:like:layout="box_count"></a>
<a class="addthis_button_tweet" tw:count="vertical"></a>
<a class="addthis_button_google_plusone" g:plusone:size="tall"></a>
<a class="addthis_counter"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js"> </script>
<!-- AddThis Button END -->
</div>
CSS
.wrapper{
height:1500px;
background: #808080;
width: 300px;
}
.container{
background: #111;
height: 600px;
}
.top{
height: 400px;
background: #7e0000;
}
.add-this-container{
position: absolute;
left: 350px;
top: 250px;
}
.addthis_floating_style{
background: #ccc;
}
p{
color: white;
}
I added a few Id’s to your html to get their positions (header and footer)
This little script will stop the floating div once it reaches the header or footer breakoff points.
I made the script to be bit ‘on the nose’ tho help you understnd what it does and when.
It can be made a bit prettier, parhaps animate the position change.
Here is the fiddle
http://jsfiddle.net/urbanbjorkman/BJ6EP/