我的问题:
- JavaScript不能在我的。php文件中工作
- 我的CSS在滚动时不工作
*CSS文件名为"var.css"
#kepala {
padding: 10px;
top: 0px;
left: 0px;
right: 0px;
position: fixed;
background - color: #EBEBEB;
height: 35px;
#kepala.scrl {
box - shadow: 0px 1px 5px rgba(0, 0, 0, 0.3);
}
*PHP文件名为"home.php"
<?php
include "koneksi.php";
session_start();
if(isset($_SESSION['username'])) {
if($_SESSION['user'] == "blabla"){
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href='var.css'>
</head>
<script type="text/JavaScript">
$(function(){
$(window).on('scroll', function(){
if ( ! $(document).scrollTop()) {
$('#kepala').removeClass('scrl');
} else {
$('#kepala').addClass('scrl');
}
});
});
</script>
<body>
<div id="kepala">
Blablabla
</div>
</body>
</html>
我只是不明白为什么我的JavaScript不工作。
当我向下滚动标题时没有效果
您正在使用jQuery,但是您还没有包含它。在脚本前的头部添加以下行:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>