Skip to content

Commit

Permalink
Merge pull request #1 from tonideleo/SimpleParallaxJS
Browse files Browse the repository at this point in the history
Simple Parallax JS - Fixed Particle JS integration with dark/light/system mode
  • Loading branch information
tonideleo authored Jul 22, 2024
2 parents bc4b78f + 5d2ecfd commit 6ded7d0
Show file tree
Hide file tree
Showing 8 changed files with 836 additions and 18 deletions.
8 changes: 7 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ last_updated: true # set to true if you want to display last updated in the foot
impressum_path: # set to path to include impressum link in the footer, use the same path as permalink in a page, helps to conform with EU GDPR
back_to_top: true # set to false to disable the back to top button

# -----------------------------------------------------------------------------
# Extra Special Settings
# -----------------------------------------------------------------------------
particle_js: true # Set the use of particle JS
simple_parallax_js: true # Set the use of Simple Parallax JS

# -----------------------------------------------------------------------------
# Theme
# -----------------------------------------------------------------------------
Expand All @@ -39,7 +45,7 @@ repo_trophies:
# will use title and url fields
# Take a look to https://github.com/jekyll/jekyll-feed for more customization

rss_icon: true
rss_icon: false

# -----------------------------------------------------------------------------
# Layout
Expand Down
1 change: 0 additions & 1 deletion _layouts/about.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ layout: default
{% endif %}
</div>
{% endif %}

<div class="clearfix">{{ content }}</div>

<!-- News -->
Expand Down
4 changes: 2 additions & 2 deletions _layouts/bib.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
<div class="row">
{% if site.enable_publication_thumbnails %}
<div class="col col-sm-2 abbr">
<div class="col col-sm-4 abbr">
{%- if entry.abbr -%}
{%- if site.data.venues[entry.abbr] -%}
{% assign venue_style = null %}
Expand Down Expand Up @@ -34,7 +34,7 @@
include figure.liquid
loading="eager"
path=entry_path
sizes = "600px"
sizes = "750px"
class="preview z-depth-1 rounded"
zoomable=true
alt=entry.preview
Expand Down
47 changes: 42 additions & 5 deletions _layouts/default.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@

<!-- Head -->
<head>
<!-- Simple Parallax JS -->
{% if site.simple_parallax_js %}
{% if site.simple_parallax_js == true %}
{% comment %} <script defer src="https://cdnjs.cloudflare.com/ajax/libs/simple-parallax-js/5.6.2/simpleParallax.js" integrity="sha512-gbbpFS1amYeHZT44HIou1MbN9b6gmRvyBdisWdE+d/GNn1aEVbUvbnOw1Jh+nW9N5+hd3d1trhhVf0ycE5LJeg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> {% endcomment %}
<script type="module" src={{ '/assets/js/simpleParallax.js' | relative_url }}></script>
<style>
img[class^="img"] {
visibility: hidden;
transform: scale(1.2); /* Ensure images are scaled initially */
transition: transform 0s;
}
</style>
<script defer>
document.addEventListener('DOMContentLoaded', function() {
var images = document.querySelectorAll('[class^="img"]');
images.forEach(function(img) {
img.addEventListener('load', function() {
img.style.visibility = 'visible';
new simpleParallax(img, {
delay: 3,
scale: 1.3,
transition: 'cubic-bezier(0,0,0,1)'
});
});
if (img.complete) {
img.dispatchEvent(new Event('load'));
}
});
});
</script>
{% endif %}
{% endif %}

{% if page.redirect %}
{% if page.redirect == true %}
{% assign redirect = site.baseurl | append: '/' %}
Expand All @@ -19,13 +52,17 @@
<!-- Body -->
<body class="{% if site.navbar_fixed %}fixed-top-nav{% endif %} {% unless site.footer_fixed %}sticky-bottom-footer{% endunless %}">

<!-- Particle JS -->
{% if site.particle_js %}
{% if site.particle_js == true %}
<script src={{ '/assets/js/particles.js' | relative_url }}></script>
<script src={{ '/assets/js/particle-call-function.js' | relative_url }}></script>
<div id="particles-js"></div>
{% endif %}
{% endif %}

<!-- Header -->
{% include header.liquid %}
<!-- particles.js container -->
<div id="particles-js"></div>
<script src="/assets/js/particles.js"></script>
<script src="/assets/js/particle-call-function.js"></script>


<!-- Content -->
<div class="container mt-5" role="main">
Expand Down
2 changes: 1 addition & 1 deletion _sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ a:hover, a:focus {
margin-bottom: 1rem;

.preview {
image-resolution: from-image 400dpi;
image-resolution: 600dpi;
}

.abbr {
Expand Down
32 changes: 28 additions & 4 deletions assets/js/particle-call-function.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */
particlesJS.load('particles-js', '/assets/json/particles.json', function() {
console.log('callback - particles.js config loaded');
document.addEventListener("DOMContentLoaded", function () {
// Function to determine the user's system theme preference
const getSystemTheme = () => {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
return "dark";
}
return "light";
};

// Load and modify particles configuration based on the system theme
particlesJS.load('particles-js', '/assets/json/particles.json', function() {
console.log('callback - particles.js config loaded');

// Modify particle colors based on the theme
const theme = getSystemTheme();
const particles = pJSDom[0].pJS.particles;

if (theme === "dark") {
particles.color.value = '#ffffff';
particles.line_linked.color = '#ffffff';
} else {
particles.color.value = '#000000';
particles.line_linked.color = '#000000';
}

// Refresh particles.js settings
pJSDom[0].pJS.fn.particlesRefresh();
});
});
Loading

0 comments on commit 6ded7d0

Please sign in to comment.