簡體   English   中英

FB評論“再加載10條評論”按鈕點擊調用應用程序窗口調整大小事件不起作用

[英]FB comment "load 10 more comments" button click call application window resize event not working

我正在使用“ https://developers.facebook.com/docs/plugins/comments/ ” javascript SDK 在我的應用程序中加載評論。 現在我的問題是我無法在評論 iframe 中跟蹤加載更多點擊事件。 我需要跟蹤功能以根據單擊加載更多按鈕事件后加載的評論 div 高度設置父 div 高度。

我嘗試了不同的解決方案,並使用“ https://jsfiddle.net/vb4xgcmo/ ”上提供的修改后的代碼找到了一個工作示例。

window.fbAsyncInit = function () {
            FB.Event.subscribe( 'xfbml.render', function ( response ) {
                if ( $( '.fb-comments' ).length > 0 ) {
                    if ( $( '.fb-comments iframe' ).length > 0 ) {
                        iframeClickTracking( $( '.fb-comments iframe' ) );
                    }
                }
            } );
        }
        function iframeClickTracking( elm ) {
            elm.bind( 'mouseover', function () {
                console.log( 'in' );
                onIframeHeightChange( elm, function () {
                    $( '#section_1' ).css( 'height', $( '#fbv' ).height() );
                } );

            } );
            elm.bind( 'mouseout', function () {
                // If they leave the ad, then they aren't going to click. Kill the run event for resize.
                setTimeout( function () {
                    if ( elm.onIframeHeightChange ) {
                        $( '#section_1' ).css( 'height', $( '#fbv' ).height() );
                        clearTimeout( elm.onIframeHeightChange );
                    }
                }, 1000 );
            } );
        }

        function onIframeHeightChange( elm, callback ) {
            var lastHeight = elm.height(), newHeight;
            (function run() {
                newHeight = elm.height();
                if ( lastHeight != newHeight ) {
                    callback();
                }
                lastHeight = newHeight;
                if ( elm.onIframeHeightChange ) {
                    clearTimeout( elm.onIframeHeightChange );
                }
                elm.onIframeHeightChange = setTimeout( run, 1000 );
            })();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM