Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction runs in Chrome but doesn't run in Firefox says function not defined
    primarykey
    data
    text
    <p>This code runs perfectly in Chrome, but Firefox says the function <code>tile1</code> is not defined. What could be the problem?</p> <p>Also, is there any way to shorten this function? I have tried using a for-loop inside <code>tile1</code> and also an <code>if-else</code> statement but I didn't succeed. </p> <pre><code>$('div.tile').each(function(index, element) { for(var i=0;i&lt;=index;i++){ var tile1=function(){ var one ="div.tile div.one"; var two =" div.tile div.two"; var three = "div.tile div.three"; if(index==0){ one="div.tile div.one"; two="div.tile div.two"; three="div.tile div.three"; } else { one ="div.tile div.one"+index; two ="div.tile div.two"+index; three ="div.tile div.three"+index; } var $one=$(one); var $two = $(two); var $three=$(three); var oneTop = $one.top; var twoTop = $two.top; var threeTop = $three.top; delayRate += 3000; // delayRate 5 sec (5000) by default $one .delay(delayRate) .animate({top: "-100.5%"},300,easing); $two .delay(delayRate) .animate({top:"0%"},300,easing); $three .delay(delayRate) .animate({top:"100.5%"},300,easing); $one .delay(12000) .animate({top: "-200.5%"},300,easing); $two .delay(12000) .animate({top:"-100.5%"},300,easing); $three .delay(12000) .animate({top:"0"},300,easing); $one .delay(12000) .animate({top: "-100.5%"},300,easing); $two .delay(12000) .animate({top:"0"},300,easing); $three .delay(12000) .animate({top:"100.5%"},300,easing); $one .delay(15000-delayRate) .animate({top: "0"},300,easing); $two .delay(15000-delayRate) .animate({top:"100.5%"},300,easing); $three .delay(15000-delayRate) .animate({top:"200.5%"},300,easing); if(i==3){ delayRate=0; } } } window.setInterval(tile1, 3000); }); </code></pre> <p>As I called the function the <code>index</code> comes randomly like 0,3,1,2, and there are 4 divs that the index corresponds to.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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