当用户窗口滚动到特定元素时显示元素

时间:2018-10-17 14:06:55

标签: javascript html scroll window

/* Javascript */
var benefitpub=document.getElementById('pubbox');
var advbox2=document.getElementById('advbox');
if (document.body.scrollTop > benefitpub.getBoundingClientRect().top+'px'){benefitpub.style.visibility='visible';}
if (document.body.scrollTop > advbox2.getBoundingClientRect().top+'px'{advbox2.style.visibility='visible';}
<!-- CSS -->
#advbox, #pubbox{margin-top:500px;visibility:hidden;}
<!-- HTML -->
<div id="advbox">
Hello This is advbox
</div>

<div id="pubbox">
Hello this is Pubbox
</div>

以上是我的代码,请告诉我如何在窗口滚动到#advbox#pubbox元素的位置时显示元素#advbox#pubbox!我很困惑哪些地方错了。

预先感谢

0 个答案:

没有答案