I am trying two write a jquery plugin to track box entering into view and I couldn't figure out how to pass UI value to my plugin and how to use the topIn()
inside the plugin.
Basically this plugin is mean to create a null callback function boxTopIn
which is re-usable on the client side
(function($) { $.fn.boxInView = function(options) { var settings = { boxTopIn: null }; var options = $.extend(settings, options); function topIn(elem) { $(window).scroll(function() { var elemTop = $(elem).offset().top; var screenBot = $(window).height(); if (($(window).scrollTop() + screenBot) > elemTop) { if ($.isFunction(options.onComplete)) { options.onComplete.call(); } options.boxTopIn.call(); } }); } }; })(jQuery); $('#c').boxInView({ boxTopIn: function() { console.log('Box in View'); } });