[Solved] Change CSS when Scroll down using PHP [closed]


You can’t archive the same functionality in PHP, as it can’t react to DOM events or update the page (It can give data, but PHP isn’t doing the updating). You can use AJAX to call PHP on the page without reloading and it can give data that you can use.

But you can have PHP generate that code and echo it out as HTML if that’s what you are looking for, your code does not seem to need anything from the server:

<?php
echo <<<HERE
<script language="javascript">
  var fixed = false;

$(document).scroll(function() {
if( $(this).scrollTop() >= 100 ) {
    if( !fixed ) {
        fixed = true;
        $('#myDivTop').css({position:'fixed',top:0});
    }
} else {
    if( fixed ) {
        fixed = false;
        $('#myDivTop').css({position:'static'});
    }
}
});
</script>
HERE;
?>

solved Change CSS when Scroll down using PHP [closed]