jquery scroll_jQuery scroll()

jquery scroll

jQuery scroll() function triggers when the element is scrolled. This method attaches a handler, which executes when the scroll event is fired. A scroll event fires for all elements which are scrollable and it also fires for window objects.

jQuery scroll()函数在元素滚动时触发。 此方法附加一个处理程序,该处理程序在滚动事件触发时执行。 对于所有可滚动的元素,将触发滚动事件;对于窗口对象,也将触发滚动事件。

jQuery scroll() (jQuery scroll())

The syntax for using jQuery scroll() function is:

使用jQuery scroll()函数的语法为:

  • scroll()

    滚动()

This signature is used without any arguments. This method is a shortcut for .trigger( "scroll" ).

该签名不带任何参数。 此方法是.trigger( "scroll" )的快捷方式。

  • scroll(handler)

    滚动(处理)

The handler is a function, which is executed when the element gets scrolled. This method is a shortcut for .on( "scroll", handler ).

处理程序是一个函数,当元素滚动时执行。 该方法是.on( "scroll", handler )的快捷方式。

jQuery滚动示例 (jQuery scroll example)

Following example demonstrates jQuery scroll() function usage.

以下示例演示了jQuery scroll()函数的用法。

<!DOCTYPE html>
<html>
<head>
<title>jQuery Scroll</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
p {
color: green;
}
.divScroll{
border:1px solid black;
width:100px;
height:200px;
overflow:scroll;
}
</style>
<script>
var x=0;
$(document).ready(function(){
  $("div").scroll(function(){
    $("span").text(x++);
  });
});
</script>
</head>
<body>

<p><b>Scroll Event Demo</p>
<div class="divScroll">Paragraph one Paragraph two Paragraph three Paragraph four Paragraph five Paragraph  six Paragraph seven</div>
<p>Scroll event triggered <b><span>0</span></b> times.</p>

</body>
</html>

In this example, you can see that the scroll() method is triggered when you scroll in the <div> element. The handler attached to the scroll() method executes with each scroll event displays the count below the <div> element.

在此示例中,您可以看到在滚动<div>元素时触发了scroll()方法。 附加到scroll()方法的处理程序在每个滚动事件显示时在<div>元素下方显示计数。

jQuery滚动演示 (jQuery scroll demo)

You can try it yourself by scrolling in the below div section.

您可以滚动以下div部分来自己尝试。

演示地址

翻译自: https://www.journaldev.com/4981/jquery-scroll

jquery scroll

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值