Skip to content

Commit

Permalink
Fix appear on scroll - barryclark#63
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldemoura authored and nielsenramon committed Jun 14, 2017
1 parent ea828d0 commit 98abba6
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 23 deletions.
18 changes: 5 additions & 13 deletions _assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@ $('.btn-share').on('click', function() {
});

$(document).on('turbolinks:load', function () {
// Initialize ScrollAppear
if (typeof $.fn.scrollAppear === 'function') {
$('.appear').scrollAppear();
}

// Initialize fluidbox
$('.fluidbox-trigger').fluidbox();

// Track page views on Turbolinks
if (typeof ga === 'function') {
ga('send', 'pageview', location.pathname);
}

// Initialize scrollreveal
sr.reveal('.reveal', {
distance: '0',
duration: 500,
easing: 'ease-in-out',
origin: 'top',
scale: 1,
reset: false,
viewFactor: 0
});
});

window.sr = ScrollReveal({ reset: true });
40 changes: 40 additions & 0 deletions _assets/javascripts/scrollappear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;(function ($, window, document, undefined) {

var els = [];

// Public methods
var pluginApi = {
init: function() {
this.each(function() {
els.push($(this));
});

refreshVisibility(els);

$(window).scroll(function () {
refreshVisibility(els);
});
return this;
}
};

// Private Methods
var refreshVisibility = function (els) {
$.each(els, function() {
if ($(this)[0].getBoundingClientRect().top < $(window).height()) {
$(this).addClass('appeared');
}
});
};

// Attach plugin to jQuery namespace
$.fn.scrollAppear = function(method) {
if (pluginApi[method]) {
return pluginApi[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return pluginApi.init.apply(this, arguments);
} else {
$.error('Method ' + method + 'does not exist in scrollAppear.');
}
};
}(jQuery, window, document));
1 change: 0 additions & 1 deletion _assets/javascripts/vendor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//= require jquery
//= require throttle-debounce-fn/dist/throttle-debounce-fn.js
//= require fluidbox
//= require scrollreveal
//= require turbolinks/dist/turbolinks.js
//= require retinajs
1 change: 1 addition & 0 deletions _assets/stylesheets/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ $article-paginator-color-hover: $gray-lightest;
@import "modules/header";
@import "modules/highlights-dark";
@import "modules/icons";
@import "modules/scrollappear";
1 change: 1 addition & 0 deletions _assets/stylesheets/light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ $article-paginator-color-hover: $gray-darkest;
@import "modules/header";
@import "modules/highlights-light";
@import "modules/icons";
@import "modules/scrollappear";
16 changes: 16 additions & 0 deletions _assets/stylesheets/modules/_scrollappear.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// =============================================================================
// ScrollAppear
// =============================================================================

.appear {
visibility: hidden;
opacity: 0;
}

.appeared {
visibility: visible;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ about_enabled: false # Change to true if you wish to show an icon in the navigat
discus_identifier: # Add your Disqus identifier
ga_analytics: # Add your GA Tracking Id
local_fonts: false # Change to true if you wish to use local fonts
scrollappear_enabled: true # Change to false to disable
rss_enabled: true # Change to false if not
social:
dribbble: # Add your Dribbble handle
Expand Down Expand Up @@ -53,6 +54,7 @@ exclude:
- package.json
- README.md
- vendor/
- yarn.lock
gems:
- jekyll-assets
- jekyll-paginate
Expand Down
2 changes: 1 addition & 1 deletion _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<footer class="footer reveal">
<footer class="footer {% if site.scrollappear_enabled %}appear{% endif %}">
<p>
Chalk is a high quality, completely customizable, performant and 100% free
blog template for Jekyll built by
Expand Down
7 changes: 6 additions & 1 deletion _includes/javascripts.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{% javascript vendor %}

{% unless site.local_fonts %}
{% javascript webfonts %}
{% endunless %}

{% if site.scrollappear_enabled %}
{% javascript scrollappear %}
{% endif %}

{% if site.ga_analytics %}
<script>
window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
Expand All @@ -10,5 +16,4 @@
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
{% endif %}

{% javascript vendor %}
{% javascript application %}
2 changes: 1 addition & 1 deletion _includes/navigation.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav class="header-nav reveal">
<nav class="header-nav {% if site.scrollappear_enabled %}appear{% endif %}">
<a href="{{ '/' | relative_url }}" class="header-logo" title="{{ site.name }}">{{ site.name }}</a>
<ul class="header-links">
{% if site.about_enabled == true %}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/articles_by_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if site.tags[page.slug] %}
<ul class="article-list">
{% for post in site.tags[page.slug] %}
<li class="article-list-item reveal">
<li class="article-list-item {% if site.scrollappear_enabled %}appear{% endif %}">
<a href="{{ post.url | relative_url }}" title="{{ post.title }}">
<h5>{{ post.title }}</h5>
</a>
Expand Down
2 changes: 1 addition & 1 deletion _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="grid grid-centered">
<div class="grid-cell">
{% include navigation.html %}
<article class="article reveal">
<article class="article {% if site.scrollappear_enabled %}appear{% endif %}">
<header class="article-header">
<h1>{{ page.title }}</h1>
<p>{{ page.description }}</p>
Expand Down
2 changes: 1 addition & 1 deletion about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
description: ""
---

<div class="about reveal">
<div class="about {% if site.scrollappear_enabled %}appear{% endif %}">
<img src="{% asset_path 'about.jpg' %}" alt="About Nielsen Ramon header image" />
<h1>About me</h1>
<p>
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ul class="article-list">
{% for post in paginator.posts %}
<li class="article-list-item reveal">
<li class="article-list-item {% if site.scrollappear_enabled %}appear{% endif %}">
<a href="{{ post.url | relative_url }}" title="{{ post.title }}">
<h5>
{{ post.title }}
Expand Down Expand Up @@ -37,7 +37,7 @@ <h5>
</li>
{% endfor %}
{% if paginator.total_pages > 1 %}
<li class="article-pagination reveal">
<li class="article-pagination {% if site.scrollappear_enabled %}appear{% endif %}">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path }}" class="article-pagination-right">Newer posts <span class="icon icon-arrow-right"></span></a>
{% endif %}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"throttle-debounce-fn": "^1.0.1",
"fluidbox": "^2.0.5",
"retinajs": "^2.1.1",
"scrollreveal": "^3.3.5",
"turbolinks": "^5.0.0",
"webfontloader": "^1.6.28"
}
Expand Down

0 comments on commit 98abba6

Please sign in to comment.