[英]Scroll to top button won't work when implement to PHP
我絕不是一個Web開發人員,如果我遺漏了一些顯而易見的內容,請原諒我。 我試圖將這個很棒的人的“滾動回到頂部”按鈕添加到我的靜態HTML網站中,當我分成兩部分放入<head>
時,它可以完美地工作
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<div class='thetop'></div>
其余的放入我的<footer>
<div class='scrolltop'>
<div class='scroll icon'><i class="fa fa-4x fa-angle-up"></i></div>
</div>
<script>
$(window).scroll(function() {
if ($(this).scrollTop() > 50 ) {
$('.scrolltop:hidden').stop(true, true).fadeIn();
} else {
$('.scrolltop').stop(true, true).fadeOut();
}
});
$(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$(".thetop").offset().top},"1000");return false})})
</script>
因此,當我嘗試將其實現到PHP中時,仍將其分為兩部分。 就像靜態站點一樣,一個用於header.php,一個用於footer.php,但是本地站點和活動站點均不顯示任何內容。 我還將按鈕css添加到我的css文件中。
我的header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php bloginfo('title'); ?></title>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<div class='thetop'></div>
<?php wp_head(); ?>
</head>
我的footer.php
<div class='scrolltop'>
<div class='scroll icon'><i class="fa fa-4x fa-angle-up"></i></div>
</div>
<script>
$(window).scroll(function() {
if ($(this).scrollTop() > 50 ) {
$('.scrolltop:hidden').stop(true, true).fadeIn();
} else {
$('.scrolltop').stop(true, true).fadeOut();
}
});
$(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$(".thetop").offset().top},"1000");return false})})
</script>
<?php wp_footer(); ?>
</div>
</body>
</html>
然后我正在考慮將它們都添加到我的index.php中,並將它們從header.php和footer.php中刪除,但仍然無法正常工作。
任何指針將不勝感激。
將<div class='thetop'></div>
<head>
放在body
<head>
之后
在jQuery和文檔准備好之后,您應該執行此類操作。
$(document).ready(function() { $(window).scroll(function() { if ($(this).scrollTop() > 50) { $('.scrolltop:hidden').stop(true, true).fadeIn(); } else { $('.scrolltop').stop(true, true).fadeOut(); } }); $(function() { $(".scroll").click(function() { $("html,body").animate({ scrollTop: $(".thetop").offset().top }, "1000"); return false }) }) });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.