我有一个sibdebar,当用户向下滚动并到达时,我希望它始终出现在屏幕顶部,所以我使用这个帖子来寻求帮助: Make element fixed on scroll
代码:
<div class="row">
<div class="col-sm-3" id="dynamic-sidebar">
<?php dynamic_sidebar('single_post_sidebar');?>
<script>
jQuery(document).ready(function($){
var elementPosition = $('#dynamic-sidebar').offset();
$(window).scroll(function(){
if($(window).scrollTop() > elementPosition.top){
$('#dynamic-sidebar').css('position','fixed').css('top','0');
} else {
$('#dynamic-sidebar').css('position','static');
}
});
});
</script>
</div>
<div class="col-sm-9 single-post-content">
<?php the_content(); ?>
</div>
</div>
任何帮助都将不胜感激。
答案 0 :(得分:1)
查看下面的示例,我刚刚添加了样式&#34;右:0&#34;和&#34;位置:固定&#34;到col-9里面的col-3。
DataTables.net, which I use, I have to do something similar. So after the table is redndered, in javascript using jquery...
$("#tblName button).click(function(evtObj) {
var row = $(evtObj).closest("tr");
// process row.
});