gpt4 book ai didi

javascript - topfunction 未定义

转载 作者:行者123 更新时间:2023-11-28 00:57:04 24 4
gpt4 key购买 nike

你好,我想做一个滚动,当我滚动时,我会出现按钮,我可以点击并返回到顶部,但我有一个错误提示:Topfunction is not defined 而且我没有'不知道为什么它不起作用。那里有我的代码,所以如果你能帮助我,那就太好了!它用于学校元素!

window.onscroll = function() {scrollFunction()};

function scrollFunction() {
if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
document.getElementById("monBoutton").style.display = "block";
} else {
document.getElementById("monBoutton").style.display = "none";
}
}

function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
}

#monBoutton {
/*display: none;*/
position: fixed;
bottom: 20px;
right: 50%;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
color:#df5791;
/*color: white;*/
cursor: pointer;
/*padding: 15px;*/
/*border-radius: 4px;*/
background-color: #ffffff00;
}

#monBoutton:hover {
transform: scale(2);
}


::-webkit-scrollbar {
/*height: 10px;*/
width: 7px;
}

/* Track */
::-webkit-scrollbar-track {
/*box-shadow: inset 0 0 0px grey; */
/*border-radius: 20px;*/
}

/* Handle */
::-webkit-scrollbar-thumb {
background: pink;
border-radius:20px;
/*box-shadow: inset 0 0 6px rgba(0,0,0,0.5);*/
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="scrolldown.css">
<link rel="stylesheet" type="text/javascript" href="debut.js">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">

</head>
<body>

<button onclick="topFunction()" id="monBoutton" title="Go to top">
<i class="fa fa-chevron-up"></i>
</button>

<div style="background-color:black;color:white;padding:30px">Scroll</div>
<div style="background-color:lightgrey;padding:30px 30px 2500px">This example demonstrates how to create a "scroll to top" button that becomes visible when the user starts to scroll the page.</div>


</body>
</html>

最佳答案

您的代码确实有效。例如,如果您单击“运行代码段”,您会注意到该函数被触发。

出现“function is not defined”错误肯定意味着无论函数在哪里,都找不到它。您是否将它放在一个单独的文件中,并且可能缺少导入?

关于javascript - topfunction 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52897863/

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