Search code examples
javascriptscript-tag

Am I doing something wrong with my <head> or <script>


I wanted to know if I was doing something strange with my tag or tag. I have some script, that isn't running properly, but works on JS fiddle. Here is the code:

  <head>
<title>Website</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<script>
(function(){

  var parallax = document.querySelectorAll("#textPlaceOne"),
      speed = -0.5;

  window.onscroll = function(){
    [].slice.call(parallax).forEach(function(el,i){

      var windowYOffset = window.pageYOffset,
          elBackgrounPos = "50% " + (windowYOffset * speed) + "px";

      el.style.backgroundPosition = elBackgrounPos;

    });
  };

})();

</script>
</head>

Proably something stupid, but thanks if you help!


Solution

  • Write your script tag at the bottom of the page after body tag.

    If issue persists, Write debug; at the first line of your script and open the page in Chrome. Press f12, chrome will let u dubug the issue.