向下滚动一点后如何贴上div

向下滚动一点后如何贴上div,第1张

向下滚动一点后如何贴上div

你可以用

jquery

$(function(){        // Check the initial Poistion of the Sticky Header        var stickyHeaderTop = $('#stickyheader').offset().top;        $(window).scroll(function(){     if( $(window).scrollTop() > stickyHeaderTop ) {  $('#stickyheader').css({position: 'fixed', top: '0px'});  $('#stickyalias').css('display', 'block');     } else {  $('#stickyheader').css({position: 'static', top: '0px'});  $('#stickyalias').css('display', 'none');     }        });  });

注意: 不要忘记在页面中包含jquery库链接(假设您是初学者

<script src="http://pre.jquery.com/jquery-latest.min.js" type="text/javascript"></script>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5621293.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存