Reputation:
Is applying a plugin this way:
$('.zoom').zoom({
on: 'grab',
url: 'http://i.imgur.com/giJudUh.jpg'
});
any worse for performance than this way:
$('.zoom').each(function() {
$(this).zoom({
on: 'grab',
url: $(this).data('zoom-url')
});
});
I need to do it the 2nd way since the zoom url has to be different for each ".zoom" element. And doing it the 2nd way allows me to grab the unique url from a data attribute on the element itself.
Just wondering if doing it the 2nd way is bad for performance in any way.
Upvotes: 1
Views: 46
Reputation: 5964
No, in this case they do literally the same thing: https://github.com/jackmoore/zoom/blob/master/jquery.zoom.js#L85
$.fn.zoom = function (options) {
return this.each(function () {
Maybe the only difference is $('.zoom').each(...
would require $.fn.each
to be ran twice.
Upvotes: 3