打开对话框时停止功能

时间:2015-06-11 00:04:33

标签: javascript jquery jquery-ui

有一个问题要问你。我正在加载一个函数,我想在它们点击精灵后停止,然后打开一个对话框。

我该怎么做?

我的jQuery使图像以特定坐标弹出:

(function fadeInDiv(){
  var divs = $('#showSprite');
  var fadeInTime = Math.floor(Math.random()*(3000-1000+1)+1000);
  var fadeOutTime = Math.floor(Math.random()*(5000-1000+1)+1000);
  var timeThere = Math.floor(Math.random()*(50-25+1)+25);
  var elem = divs.eq(Math.floor(Math.random()*divs.length));

  var whichCord = Math.floor(Math.random()*(6-1+1)+1);

  var arrayDictionary = {
      ary1: ["39","141"],
      ary2: ["85","27"],
      ary3: ["215","166"],
      ary4: ["351","13"],
      ary5: ["389","168"],
      ary6: ["486","32"],
      ary7: ["576","150"]
    };

    if (!elem.is(':visible')) {){
        elem.fadeIn(Math.floor(Math.random()*fadeInTime),fadeInDiv);
        elem.css({
            'position':'absolute',
            'left':arrayDictionary["ary"+whichCord][0]+'px',
            'top':arrayDictionary["ary"+whichCord][1]+'px'
            });
    } 
    else {
        elem.fadeOut(Math.floor(Math.random()*fadeOutTime),fadeInDiv)
             .delay(timeThere); 
    }

})();

和我的对话:

$('#clickedSprite').dialog({
    autoOpen: false,
    title: 'What Do We Have Here?'
});
$('#sprite').click(function() {

    var palID = $(this).attr('palID');
    var petID = $(this).attr('petID');
    var securePass = $(this).attr('securePass');
    var timePassed = new Date().getTime() / 1000;
    $.cookie("hashing", securePass);
    $.cookie("timePassed", Math.round(timePassed));

    $('#clickedSprite').dialog('open');

    return false;
});

1 个答案:

答案 0 :(得分:0)

使用!$(".ui-dialog").length检查没有对话框:

(function fadeInDiv() {
    if(!$(".ui-dialog").length){
        var divs = $('#showSprite');
        var fadeInTime = Math.floor(Math.random() * (3000 - 1000 + 1) + 1000);
        var fadeOutTime = Math.floor(Math.random() * (5000 - 1000 + 1) + 1000);
        var timeThere = Math.floor(Math.random() * (50 - 25 + 1) + 25);
        var elem = divs.eq(Math.floor(Math.random() * divs.length));
        var whichCord = Math.floor(Math.random() * (6 - 1 + 1) + 1);
        var arrayDictionary = {
            ary1: ["39", "141"],
            ary2: ["85", "27"],
            ary3: ["215", "166"],
            ary4: ["351", "13"],
            ary5: ["389", "168"],
            ary6: ["486", "32"],
            ary7: ["576", "150"]
        };
        if (!elem.is(':visible')) {) {
            elem.fadeIn(Math.floor(Math.random() * fadeInTime), fadeInDiv);
            elem.css({
                'position': 'absolute',
                    'left': arrayDictionary["ary" + whichCord][0] + 'px',
                    'top': arrayDictionary["ary" + whichCord][1] + 'px'
            });
        } else {
            elem.fadeOut(Math.floor(Math.random() * fadeOutTime), fadeInDiv)
                .delay(timeThere);
        }
    }
})();