gpt4 book ai didi

javascript - 如何创建 HTML+jScript 滚动触发框

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:22 25 4
gpt4 key购买 nike

我在 Blogger.com 上有一个博客,我想添加一个滚动触发框,例如 Dreamgrow 或 Wordpress 的 Qoate 滚动触发框。我提到了Scroll Triggered Box with jQuery .我创建了一个 HTML 文件并对其进行了测试,但这对我不起作用。可能是我在某个地方弄错了。我的编码是

<html>

<head>

<title>Scroll Triggered Box With jQuery</title>

<style type="text/css">
.Comments
{
font:georgia;
display:none;
}


</style>

</head>

<body>

<script type="text/javascript">
$(document).ready(function () {
$(window).scroll(function () {
var y = $(window).scrollTop();
var c = $('#comments').offset();
if (y > (c.top - $(window).height())) {
$('#the_box').fadeIn("slow");
} else {
$('#the_box').fadeOut('slow');
}
});
});
</script>

<div>
<!--My long post here-->
</div>

<div class="Comments" id="the_box">
This is the DIV that triggers I scroll down to Comments</br>
This is the DIV that triggers I scroll down to Comments</br>
This is the DIV that triggers I scroll down to Comments</br>
This is the DIV that triggers I scroll down to Comments</br>
This is the DIV that triggers I scroll down to Comments</br>
This is the DIV that triggers I scroll down to Comments
</div>

</body>

</html>

我在 jScript 方面有点弱。我不知道 jScript 是如何工作的。

我怎样才能解决我的问题并让它在我的 Blogger.com 博客中正常工作?

最佳答案

我可以看出您的代码乱七八糟。

  var a =$(window).height();
var num = c-y;
if (y > num){
do your function
}else{
do whatever
}

关于javascript - 如何创建 HTML+jScript 滚动触发框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13276165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com