jQuery UI的效应导致的iframe重装(jQuery UI effect causes if

2019-08-16 23:29发布

我使用jQuery来显示/隐藏它恰好包含一个iframe一个div。 它的伟大工程只用标准的“显示”和“隐藏”的方法。

所以现在我想获得一点点花哨,并添加从jQuery UI的一些影响( http://jqueryui.com/effect/ ),但突然我的iframe会越来越重装我每次显示/隐藏他们的时间。

这里是一个小提琴证明: http://jsfiddle.net/BnZzk/1/这里是因为SO迫使我补充它的代码:

<style>
div {
    height: 200px
}
span {
    display: block;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid black;
}
</style>

<div>
    <iframe src="http://www.wikipedia.org/"></iframe>
</div>
<input type="button" value="Go"/>
<hr/>
<div id="msgs"></div>

<script>
$(function () {

var container = $('div'),
    ifrm = $('iframe'),
    msgs = $('#msgs')
    delay = 10; //change me to adjust delay in seconds between actions

$('input').on('click', normal);
log('First let the iframe load and then clear your network console -- click the "Go" button to get started.');

function log (msg) {
    msgs.append('<span>' + msg + '</span>');
}

function normal () {

    ifrm.
        hide(400, function () {

            log('That was a standard hide with no effect -- is your network console still empty? OK we\'ll pause for ' + delay + ' seconds and then do a standard show.');

            ifrm.
                delay(delay * 1000).
                show(400, function () {
                    log('That was a show with no effect -- is you network console *still* empty? Great! Let\'s try some effects.');
                    log('------------------------<br/>' +
                    '-- Begin Effects --<br/>' +
                    '------------------------<br/>');
                    withEffect();
                });

        }); //hide

} //normal

function withEffect () {

    log('We\'ll pause for another ' + delay + ' seconds -- get ready to watch your network console.');

    ifrm.
        delay(delay * 1000).
        hide('fold', {mode:'hide'}, 400, function () {

            log('That was a hide with effect -- is your network console flooded? Mine too :-( We\'ll wait ' + delay + ' seconds while you clear your console again.');

            ifrm.
                delay(delay * 1000).
                show('fold', {mode:'show'}, 400, function () {
                    log('That was a show with effect -- is your network console flooded again? Bummer ...');
                });

        }); //hide

} //withEffect

});
</<script>

任何想法我怎么能保持奇特的效果,但不会刷新我的I帧的内容?

Answer 1:

它的发生,因为这种效应整改DOM,把一个DIV包装周围的IFRAME,所以当IFRAME是“reappended”重装发生! 您可以看到使用谷歌Chrome元素检查这种行为。

为了解决我建议你从你的IFRAME适用于父DIV的效果,但不使用effect插件。 退房http://api.jquery.com/animate/ ,操纵宽度和高度样式属性。



Answer 2:

作为@Jamillo桑托斯的答案,“reappend”的iFrame的问题。

如果您正在使用对话框控件或其 jQueryUI的扩展 ,并要防止这种情况,只需重新定义你的widget实现的_moveToTop()函数如下。

_moveToTop: function() {
    return null;
},


文章来源: jQuery UI effect causes iframe reload