I have added the library for Bootstrap and data-spy attribute where I want to make the div fix when I scroll the page down. But it doesn't work, I have almost tried everything, but not able to figure out the problem. Is is something like the data-spy attribute doesn't work on class = "row" ? Here's my code for HTML.
<div class="row">
<h4> HEADING </h4>
<h5>
<div class="row" data-spy="affix" data-offset-top="10">
dsds
Date : <input type="date" name="graph_date" id="graph_date">
</div>
<div class="row">
<div class="graph-hourly">
<div class="loader" id="chart_loader">
<p>Loading...</p>
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_hourly"></div>
</div>
</div>
</div>
and some css :
.affix {
top : 0;
width: 80%;
}
after searching for some solutions, I've added this also,
.affix-top {
width: 100%;
}
.affix-bottom {
position: absolute;
width: 100%;
}
but this solution also dosen't worked for me.
First of all delete
top:0;
from affix class because it will make a issue for you.now you have two methods pick a one :
1
adding
data-spy="affix"
which is works fine for me2
same result ass
data-spy
but you will need some styling after you complete your pageby adding a
position
Property forinput
tagas ex. : CSS:
and HTML :
Update 1
this Jquery code can detect a scroll event so when user scroll down it will make the
div
tag sticky or "affix"change the
aTop
variable with the height you want (in pixel) so when the user scroll down 100px the div become stickya JSfiddle example
Update 1.1
a bit smarter Jquery code do the same but get the height automatically from a another element this can be good if you format your page to something similar to this