Skip to content

Instantly share code, notes, and snippets.

@hollyboom
Forked from srikat/jack-in-the-box-init.js
Created March 18, 2016 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hollyboom/7cd377bd0ae4d3e7c505 to your computer and use it in GitHub Desktop.
Save hollyboom/7cd377bd0ae4d3e7c505 to your computer and use it in GitHub Desktop.
Scroll animations in WordPress using Animate.css, Jack In The Box and Waypoints. http://sridharkatakam.com/scroll-animations-wordpress-using-animate-css-jack-box-waypoints/
jQuery(function() {
<?php
//* Do NOT include the opening php tag
add_filter('post_class', 'animate_css_class');
function animate_css_class($classes) {
$classes[] = 'box slideInLeft';
return $classes;
}
<?php
//* Do NOT include the opening php tag
add_action( 'wp_enqueue_scripts', 'enqueue_scroll_animations' );
function enqueue_scroll_animations() {
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/css/animate.min.css' );
wp_enqueue_script( 'jack-in-the-box', get_stylesheet_directory_uri() . '/js/jack-in-the-box.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'jack-in-the-box-init', get_stylesheet_directory_uri() . '/js/jack-in-the-box-init.js', array( 'jack-in-the-box' ), '1.0.0', true );
wp_enqueue_script( 'waypoints', get_stylesheet_directory_uri() . '/js/waypoints.min.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'waypoints-init', get_stylesheet_directory_uri() .'/js/waypoints-init.js' , array( 'jquery', 'waypoints' ), '1.0.0' );
}
<?php
//* Do NOT include the opening php tag
add_action( 'wp_enqueue_scripts', 'enqueue_scroll_animations' );
function enqueue_scroll_animations() {
if ( is_handheld() )
return;
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/css/animate.min.css' );
wp_enqueue_script( 'waypoints', get_stylesheet_directory_uri() . '/js/waypoints.min.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'waypoints-init', get_stylesheet_directory_uri() .'/js/waypoints-init.js' , array( 'jquery', 'waypoints' ), '1.0.0' );
}
jQuery(function($) {
$('.genesis-nav-menu .menu-item.alignleft').waypoint(function() {
$(this).toggleClass( 'animated swing' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.footer-widgets-1').waypoint(function() {
$(this).toggleClass( 'animated slideInLeft' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.footer-widgets-2').waypoint(function() {
$(this).toggleClass( 'animated fadeInUpBig' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.footer-widgets-3').waypoint(function() {
$(this).toggleClass( 'animated slideInRight' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.home-middle, #featured-post-5 .entry').waypoint(function() {
$(this).toggleClass( 'animated slideInLeft' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.after-entry').waypoint(function() {
$(this).toggleClass( 'animated pulse' );
},
{
offset: '100%',
// triggerOnce: true
});
$('.category .entry, .search .entry').waypoint(function() {
$(this).toggleClass( 'animated fadeInUp' );
},
{
offset: '100%',
// triggerOnce: true
});
});
(function($) {
<?php
//* Do NOT include the opening php tag
add_action( 'wp_enqueue_scripts', 'enqueue_scroll_animations' );
function enqueue_scroll_animations() {
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/css/animate.min.css' );
wp_enqueue_script( 'jack-in-the-box', get_stylesheet_directory_uri() . '/js/jack-in-the-box.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'jack-in-the-box-init', get_stylesheet_directory_uri() . '/js/jack-in-the-box-init.js', array( 'jack-in-the-box' ), '1.0.0', true );
}
<?php
//* Do NOT include the opening php tag
add_filter( 'genesis_attr_sidebar-primary', 'custom_genesis_attributes_sidebar_primary' );
/**
* Add attributes for primary sidebar element.
*
* @since 2.0.0
*
* @param array $attributes Existing attributes.
*
* @return array Amended attributes.
*/
function custom_genesis_attributes_sidebar_primary( $attributes ) {
$attributes['class'] = 'sidebar sidebar-primary widget-area box slideInDown';
$attributes['role'] = 'complementary';
$attributes['itemscope'] = 'itemscope';
$attributes['itemtype'] = 'http://schema.org/WPSideBar';
return $attributes;
}
jQuery(document).ready(function($) {
$('body').jackInTheBox();
});
(function() {
(function($) {
$.jackInTheBox = function(element, options) {
var state,
_this = this;
state = '';
this.settings = {};
this.$element = $(element);
this.getSetting = function(key) {
return this.settings[key];
};
this.callSettingFunction = function(name, args) {
if (args == null) {
args = [];
}
return this.settings[name].apply(this, args);
};
this.mobileDevice = function() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
};
this.visible = function($box) {
var bottom, top, viewBottom, viewTop;
viewTop = _this.$window.scrollTop();
viewBottom = viewTop + _this.$window.height() - _this.settings.offset;
top = $box.offset().top;
bottom = top + $box.height();
return top <= viewBottom && bottom >= viewTop;
};
this.scrollHandler = function() {
return _this.$window.scroll(function() {
return _this.show();
});
};
this.show = function() {
return _this.$boxes.each(function(index, box) {
var $box;
$box = $(box);
if (_this.visible($box)) {
return $box.css({
visibility: 'visible'
}).addClass(_this.settings.animateClass);
}
});
};
this.init = function() {
this.settings = $.extend({}, this.defaults, options);
this.$window = $(window);
this.$boxes = $("." + this.settings.boxClass).css({
visibility: 'hidden'
});
if (this.$boxes.length) {
this.scrollHandler();
return this.show();
}
};
if (!this.mobileDevice()) {
this.init();
}
return this;
};
$.jackInTheBox.prototype.defaults = {
boxClass: 'box',
animateClass: 'animated',
offset: 0
};
return $.fn.jackInTheBox = function(options) {
return this.each(function() {
var plugin;
if ($(this).data('jackInTheBox') === void 0) {
plugin = new $.jackInTheBox(this, options);
return $(this).data('jackInTheBox', plugin);
}
});
};
})(jQuery);
}).call(this);
.category .entry, .search .entry {
-webkit-animation-duration: 1.8s;
-moz-animation-duration: 1.8s;
animation-duration: 1.8s;
}
.genesis-nav-menu .menu-item.alignleft {
-webkit-animation-delay: 2s;
-moz-animation-delay: 2s;
animation-delay: 2s;
}
jQuery(function($) {
$('.entry').waypoint(function() {
$(this).toggleClass( 'animated slideInLeft' );
},
{
offset: '100%',
// triggerOnce: true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment