更新時間:2022-03-15 09:44:34 來源:動力節(jié)點 瀏覽1192次
scroll() 是 jQuery 中的一個內(nèi)置方法,用于用戶在指定元素中滾動。此方法適用于所有可滾動元素和瀏覽器窗口。
句法:
$(選擇器).scroll(函數(shù))
參數(shù):此方法接受可選的單參數(shù)函數(shù)。用于指定觸發(fā)滾動事件時要運行的函數(shù)。
返回值:當(dāng)指定元素發(fā)生滾動時,它綁定一個事件。
下面的程序說明了 jQuery 中的 scroll() 方法:
例子:
<!DOCTYPE html>
<html>
<head>
<title>scroll method</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- jQuery code to show the working of this method -->
<script>
$(document).ready(function() {
$("div").scroll(function() {
alert("scroll happened");
});
});
</script>
<style>
div {
border: 1px solid black;
width: 500px;
height: 100px;
overflow: scroll;
}
</style>
</head>
<body>
<!-- scroll inside this div box -->
<div>Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!
Welcome to GeeksforGeeks!.
Welcome to GeeksforGeeks!
</div>
</body>
</html>
輸出:
在 div 框內(nèi)滾動后。
以上就是關(guān)于“jQuery滾動的示例”介紹,大家如果對此比較感興趣,想了解更多相關(guān)知識,不妨來關(guān)注一下動力節(jié)點的Java在線學(xué)習(xí),里面的課程內(nèi)容細(xì)致全面,從入門到精通,很適合沒有基礎(chǔ)的小伙伴學(xué)習(xí),希望對大家能夠有所幫助。