0
我有我的index.php
這是固定的按鈕,當用戶在頁面的底部的頂部工作。創建回到頂部按鈕使用jquery面臨的問題與代碼
<button id="fixed-btn"></button>
和它的CSS是這樣的。
#fixed-btn{
position: fixed;
bottom: 50px;
right: 50px;
height: 30px;
width: 30px;
border-radius: 100%;
background-color: red;
opacity: 0;
}
#fixed-btn.show{
opacity: 1;
}
這樣做的我寫的jQuery
$(document).ready(function()
{
function testScroll(ev)
{
if(window.pageYOffset>400)
{
$('#fixed-btn').addClass('show');
}
else
{
$('#fixed-btn').removeClass('show');
}
}
window.onscroll=testScroll
$("#fixed-btn").click(function()
{
$('html, body').animate(
{
scrollTop:0
}, 1500);
});
我不知道爲什麼它不working.button是不可見的。任何人都可以有想法,然後請分享。感謝提前:)
你有沒有嘗試在css中z-index? @foram –
它適合我。檢查https://jsfiddle.net/ou5rrww6/ –
你想念這個'});'在最後 –