My problem :
*CSS Files named "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 Files named "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>
I just can't understand why my JavaScript doesn't work.
There is no effect when I'm scrolling down the header.
You're using jQuery, but you haven't included it. Add the following line in the head before your script:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>