Skip to content

Instantly share code, notes, and snippets.

@ewebdev
Created February 26, 2014 14:15
Show Gist options
  • Save ewebdev/9230174 to your computer and use it in GitHub Desktop.
Save ewebdev/9230174 to your computer and use it in GitHub Desktop.
(function ($) {
$.fn.linkOut = function (options) {
return this.each(function () {
$(this).on('mouseenter', options.mouseEnterToSelector, function () {
var $el = $(this),
$target = $el.find(options.targetAppendSelector);
if ($target.length) {
var $linkout = $('<a />', {class: 'linkout sprite', rel: 'nofollow', css: {opacity: 0}, href: $target.data('href')}).appendTo($target);
$linkout
.on('click', function (e) {
window.open($target.data('href'));
e.preventDefault();
e.stopPropagation();
});
$el.one('mouseleave', function () {
$linkout.remove();
});
setTimeout(function () {
$linkout.css({opacity: ''});
}, 1);
}
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment