jekyllgithub-pagesparallax.js

Can jekyll support parallax effect?


I created a blank jekyll blog and I included parallax.js with CDNlink and the link is : (script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js">) but when I ran it in localhost the moving effect that I have imported doesn't work. In my rails app that I created it works perfect there.Also if I deploy it on GITHUB pages will the parallax work there?What should I do to fix that issue? I upload in github pages https://lazospap.github.io/LazPap/. There are a lot to be fixed but for now i can't see the images.


Solution

  • YES, parallax effect can work on Github pages.

    You probably just made some coding errors/mistakes.


    Rules to follow

    1. Nothing can be placed after </body></html>
    The first mistake I see is that nothing can be placed after </body></html>. Your layout file contains this:

      </body>
    </html>
    <!-- Bootstrap core JavaScript -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/jquery/jquery.min.js"></script>
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    
    <!-- Plugin JavaScript -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/jquery-easing/jquery.easing.min.js"></script>
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/magnific-popup/jquery.magnific-popup.min.js"></script>
    
    <!-- Custom scripts for this template -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/js/creative.min.js"></script>
    

    It should be:

    <!-- Bootstrap core JavaScript -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/jquery/jquery.min.js"></script>
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    
    <!-- Plugin JavaScript -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/jquery-easing/jquery.easing.min.js"></script>
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/vendor/magnific-popup/jquery.magnific-popup.min.js"></script>
    
    <!-- Custom scripts for this template -->
    <script src="https://blackrockdigital.github.io/startbootstrap-creative/js/creative.min.js"></script>
    
    </body></html>
    

    2. Open and close the body only once
    You embed the content in your layout. Your layout has a body open and a body close tag... however, your content also has a body open and a body close tag. Therefore you open and close the body of your HTML file twice. Remove it in your content file and your are set. Find <body id="page-top"> and </body> in this file and this file and remove them.

    3. Use layouts for (complex) HTML and JS
    The code < 150 on line 184 gets wrongfully escaped. This is probably due to the fact that you are writing complex HTML and JS in a markdown file. You could prevent this by combining the HTML from 'index.md' and 'default.html' in a file 'home.html' in your layout directory. Your index.md file should then reference 'home' as layout instead of 'default'. Here is the error:

    SyntaxError: missing ) after conditionLazPap:184:34
    

    4. Call functions only after they are declared
    I know it gets kind of hard to grasp when you use 'defer', but the rule of thumb is to call a function only after you have declared it. Parallax is a function that gets declared in line 71 of default.html:

    <script type="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js"></script>
    

    But you call the function inside the content part of that same file on line 38. That does not work, and if it does it is solely due to the 'defer' statement.

    5. Use a baseurl
    When you host on Github Pages you need a basurl. The reference to your images is /images/HTML_5.png. Because you host on Github pages your baseurl should be /LazPap so your url becomes /LazPap/images/HTML_5.png. More reading about baseurl...


    A simpler solution...

    You started out with a copy of this code: https://blackrockdigital.github.io/startbootstrap-creative/. The easiest way to achieve a parallax-like effect would be to add JUST ONE CSS rule to the original code:

    header.masthead {background-attachment: fixed;}
    

    Although it is the solution I would use, it is probably not what you want, as you specifically mentioned parallax and a javascript solution.