簡體   English   中英

在jQuery中添加異常

[英]Add exception in jQuery

我的頭文件中包含此代碼,該文件將所有頁面滾動到特定的錨點。

我想為我的主頁添加一個例外,因此代碼無法在其中工作。

// this code is between <head> tags in my header file.
<script
function scroll(){
$('html, body').animate({
    scrollTop: $('#scroll').offset().top
    }, 1000);

}
</script>

// this code is at the bottom of the page in my header file
// anchor
<a href="#scroll" id="scroll"></a>

// this code is in the header file
// called
<body onload="scroll()">

您可以使用以下方法覆蓋scroll()函數

function scroll(){
 // this function do nothing

}

並將其放在相關標簽的適當位置,例如頁面頂部或頁面末尾

例如

<html>
<head>
<script>
function scroll()
{
alert(1);
}
</script>
</head>

<body onload="scroll()">
body text

<script>
function scroll()
{
alert(2);
}
</script>

</body>
</html>

此代碼運行alert(2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM