Skip to content

Instantly share code, notes, and snippets.

@dpmango
Created October 8, 2017 23:59
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 dpmango/607111002c1ae3ca5a7d60dacdef4391 to your computer and use it in GitHub Desktop.
Save dpmango/607111002c1ae3ca5a7d60dacdef4391 to your computer and use it in GitHub Desktop.
// TELEPORT PLUGIN
$('[js-teleport]').each(function (i, val) {
var self = $(val)
var objHtml = $(val).html();
var target = $('[data-teleport-target=' + $(val).data('teleport-to') + ']');
var conditionMedia = $(val).data('teleport-condition').substring(1);
var conditionPosition = $(val).data('teleport-condition').substring(0, 1);
if (target && objHtml && conditionPosition) {
_window.resized(100, function () {
teleport()
})
function teleport() {
var condition;
if (conditionPosition === "<") {
condition = _window.width() < conditionMedia;
} else if (conditionPosition === ">") {
condition = _window.width() > conditionMedia;
}
if (condition) {
target.html(objHtml)
self.html('')
} else {
self.html(objHtml)
target.html("")
}
}
teleport();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment