更新時(shí)間:2022-03-15 09:44:34 來源:動(dòng)力節(jié)點(diǎn) 瀏覽1095次
scroll() 是 jQuery 中的一個(gè)內(nèi)置方法,用于用戶在指定元素中滾動(dòng)。此方法適用于所有可滾動(dòng)元素和瀏覽器窗口。
句法:
$(選擇器).scroll(函數(shù))
參數(shù):此方法接受可選的單參數(shù)函數(shù)。用于指定觸發(fā)滾動(dòng)事件時(shí)要運(yùn)行的函數(shù)。
返回值:當(dāng)指定元素發(fā)生滾動(dòng)時(shí),它綁定一個(gè)事件。
下面的程序說明了 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)滾動(dòng)后。
以上就是關(guān)于“jQuery滾動(dòng)的示例”介紹,大家如果對(duì)此比較感興趣,想了解更多相關(guān)知識(shí),不妨來關(guān)注一下動(dòng)力節(jié)點(diǎn)的Java在線學(xué)習(xí),里面的課程內(nèi)容細(xì)致全面,從入門到精通,很適合沒有基礎(chǔ)的小伙伴學(xué)習(xí),希望對(duì)大家能夠有所幫助。
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)
初級(jí) 202925
初級(jí) 203221
初級(jí) 202629
初級(jí) 203743