Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way to take an OOP approach to this might be something like this. The <code>min</code> and <code>max</code> values are members of the object stored in <code>objVar</code>. This is very much like the object representing the min and max values you were looking for. Why not take it a step or two further, though? </p> <p>We can include the <code>inScroller()</code> function. Now, since it's a part of the object, it can access <code>objVar.min</code> and <code>objVar.max</code> directly and doesn't need to have them passed to it. You can just call <code>objVar.inScroller();</code> and it will operate on the variables <code>objVar.min</code> and <code>objVar.max</code>.</p> <p>So what about incrementing by 10? Extending that same concept, we can create a function that increments the <code>objVar.min</code> and <code>objVar.max</code> variables and simply call it thusly: <code>objVar.increment();</code>. </p> <p>Next time that <code>objVar.inScroller();</code> is called, <code>objVar.min</code> and <code>objVar.max</code> will have been incremented by 10 each. You could even put 'em in a loop, like: </p> <p><code>for (int i=0;i&lt;totalRuns;i++) { objVar.inScroller(); objVar.increment(); } </code></p> <p>The Object:</p> <pre><code>var objVar = new function() { this.min = 0; this.max = 10; this.increment() = function() { min += 10; max += 10; } this.inScroller = function() { for (var i=min;i&lt;max;i++) { var pic = $('.scrolling p')[i], pic = $(pic).text(), var img = $('&lt;img /&gt;').attr("src","img/profile/" + pic).css('display','none'); $('.pfiles').append(img); $('img').load(function() { $(this).fadeIn(400) }); } } </code></pre> <p>Finally, it's called thusly:</p> <pre><code>$(window).scroll(function() { if ($(window).scrollTop() + window.innerHeight &gt;= $('.pfiles').height() &amp;&amp; $('.scrolling p').length &gt; $('.pfiles img').length) { objVar.increment(); objVar.inScroller(); } }); </code></pre> <p>Or even thusly:</p> <pre><code>$(window).scroll(function() { if ($(window).scrollTop() + window.innerHeight &gt;= $('.pfiles').height() &amp;&amp; $('.scrolling p').length &gt; $('.pfiles img').length) { for (int i=0;i&lt;totalRuns;i++) { objVar.inScroller(); objVar.increment(); } } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload