【问题标题】:What is causing jQuery UI to slide instead of fade?是什么导致 jQuery UI 滑动而不是淡出?
【发布时间】:2017-11-06 12:33:39
【问题描述】:

我正在使用 jQueryUI 和 Polymer 弹出对话框,我正在隐藏一个 div,然后从 ajax 加载个人资料照片的数据,并使用图像元素填充 div 并使其淡入。据我所知,它在另一个部分以相同的方式执行此操作,该部分很好地淡入而不是滑动。我在这里删除了很多代码,因为我发现它对问题没有影响。

function supervisorAccountPopup(e) {

    var button = e.target;

    while (!button.hasAttribute('data-dialog') && button !== document.body) {
        button = button.parentElement;
    }


    if (!button.hasAttribute('data-dialog')) {

        return;

    }

    var dialogID = button.getAttribute('data-dialog');
    var dialog   = document.getElementById(dialogID);

    if (dialog) {

    $('#supervisorPopupProfilePic').hide();


        dialog.open();

        $.ajax({
            type: 'POST',
            url: 'getProfileImage.php',
            data:{'userID':<? echo $createdByID; ?>, 
                  'size'  :'big'},
            tryCount:0,
            retryLimit:5,
            cache:false,
            success: function(data) {   

                var profileData = JSON.parse(data);

                if(profileData[0].profilePhotoFullpath != ""){

                    $('#supervisorPopupProfilePic').html("<img class='profileImgPopup' id='supervisorPopupProfilePicIMG' src='uploads/profile/" + profileData[0].profilePhotoFullpath + "?" + new Date().getTime() + "'>");

                    var supervisorPopupProfilePic = document.getElementById('supervisorPopupProfilePicIMG');

                    supervisorPopupProfilePic.onload = function () {
                        $('#supervisorPopupProfilePic').show('fade');       
                    };

                }else{

                    $('#supervisorPopupProfilePic').html("<img id='supervisorPopupProfilePicIMG' class='profileImgPopup' src='uploads/profile/_default/defaultProfileImage_big_noBorder.png'>");

                    var supervisorPopupProfilePic = document.getElementById('supervisorPopupProfilePicIMG');

                    supervisorPopupProfilePic.onload = function () {
                        $('#supervisorPopupProfilePic').show('fade');       
                    };

                }


            },
            error : function(xhr, textStatus, errorThrown ) {

                this.tryCount++;

                if (this.tryCount <= this.retryLimit) {
                    //try again
                    $.ajax(this);
                    return;
                }    

                return;

            }
        });

     }

}

【问题讨论】:

    标签: jquery jquery-ui polymer slide fade


    【解决方案1】:

    您在此处使用淡入淡出选项:$('#supervisorPopupProfilePic').show('fade');

    如果您只需要单个操作,则可以使用 slideToggle() 或 slideDown() 将内容滑入和滑出。你不需要 show();

    button.click(function() {
      $('#supervisorPopupProfilePic').slideToggle( "slow", function() {
    
      });
    });
    

    button.click(function() {
      $('#supervisorPopupProfilePic').slideDown( "slow", function() {
    
      });
    });
    

    【讨论】:

    • 不,我是说它现在正在滑动,但我不希望它滑动。我希望它褪色,但由于某种原因它在滑动。
    猜你喜欢
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 2023-03-18
    相关资源
    最近更新 更多