Skip to content

Instantly share code, notes, and snippets.

@benjamminf
benjamminf / parallax.js
Last active November 9, 2016 22:22
parallax.js
import $ from 'jquery'
// Request animation frame polyfills
const frame = window.requestAnimationFrame ? cb => requestAnimationFrame(cb) : cb => setTimeout(cb, 0)
const unframe = window.cancelAnimationFrame ? id => cancelAnimationFrame(id) : id => clearTimeout(id)
// Trigger layout redraws around some element
const redraw = el => (el instanceof $ ? el[0] : el).offsetWidth
// Memoize viewport height so using it is less expensive
@benjamminf
benjamminf / neo_create_block.php
Last active July 31, 2017 17:49
Create Neo block and save it to entry
<?php
// Get the entry model. This could really be any element model, such as a category or Craft Commerce product.
$entry = craft()->entries->getEntryById(1234);
// Get the Neo field model and the field type model.
$field = craft()->fields->getFieldByHandle('neoFieldHandle');
$fieldType = $field->getFieldType();
$fieldType->setElement($entry);