打破javascript中的每个功能 [英] Breaking the each function in javascript

查看:56
本文介绍了打破javascript中的每个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi





我正在使用每个函数循环数组。我们正在做一些动画类的事情。我们正在改变表格中td元素的背景颜色。我们有带有td元素的数组。如果我们点击任何一个td元素,它会遍历该数组并开始改变数组中每个td的背景颜色。我们有一个停止按钮,(暂停和开始(在同一个按钮中))。当我点击停止按钮时,它完全停止。当我点击暂停时,它必须停止然后在那里,如果我再次点击开始按钮,它必须从那里开始。我们写的是什么逻辑,当我们点击停止时,我们将1分配给全局变量变量按钮为该全局变量赋值0。在每个循环中,保持逻辑,如果全局变量是



全局变量是1运行循环,否则break(返回false)loop.only暂停工作。



如果有人帮助我,请提前致谢。













以下是代码详情。



 function GenrateDecessionLineAnimate1()
{
count = 1 ;

var delay = 100 ;
var total = DecessionLineAnimateList1.length;

$(DecessionLineAnimateList1).each(function(){

var fnc = function(y){< span class =code-keyword> return function(){
if (count == 1 ){

$(y).css(' background- color'' red'); $(y).focus()}
其他 返回 false ;
}}( this

var fnc2 = function(y ){ return function(){
if (count == 1 ){
$(y).css(' 返回ground-color'' #efefef'); }
else return false ; ( this

setTimeout(fnc,delay);
setTimeout(fnc2,delay + 2000 );
delay + = 2000 ;
});





停止按钮点击事件调用下面的metod。



  var  count =  1 ; 

函数PauseAnimation()
{
if (count == 1
count = 0 ;
else count = 1 ;

}

解决方案

(DecessionLineAnimateList1).each(function(){

var fnc = function(y){ return function(){
if (count == 1 ){


(y).css(< span class =code-string>' background-color'' red');


(y).focus()}
else 返回 false ;
}}( this

var fnc2 = function(y){ return function(){
if (count == 1 < /跨度>){

hi


I''m looping the array using each function. we are doing some animation kind of thing. we are changing the back ground color of td element in the table.we have array with td elements. if we click on any of the td elements,it loop through that array and start changing the back ground color of the each td in the array.we have 1 stop button ,(pause and start(in the same button)). when i click on stop button, it has stop entirely. when i click on pause, it has to stop then and there, if i again click on start button,it has to start from there.what logic we have written is, we are assigning 1 to Global variable variable, when we click on stop button assigning 0 to that Global variable. in the each loop, kept logic like if Global variable is

global variable is 1 run the loop else break(return false) the loop.only pause is working.

Thanks in advance, if some one helps me.






below are the code details.

function GenrateDecessionLineAnimate1()
{
count=1;

   var delay = 100;
   var total=DecessionLineAnimateList1.length;

    $(DecessionLineAnimateList1).each(function () {

        var fnc = function (y) { return function () {
        if(count ==1){

        $(y).css('background-color', 'red'); $(y).focus() }
        else return false;
         }} (this)

        var fnc2 = function (y) { return function () {
        if(count ==1){
         $(y).css('background-color', '#efefef'); }
         else return false; }} (this)

        setTimeout(fnc, delay);
        setTimeout(fnc2, delay + 2000);
        delay += 2000;
           });



on the stop button click event calling the below metod.

var count =1;

 function PauseAnimation()
    {
    if(count == 1)
    count=0;
    else count=1;

    }

解决方案

(DecessionLineAnimateList1).each(function () { var fnc = function (y) { return function () { if(count ==1){


(y).css('background-color', 'red');


(y).focus() } else return false; }} (this) var fnc2 = function (y) { return function () { if(count ==1){


这篇关于打破javascript中的每个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆