为什么$(window).resize()不适合我?

时间:2016-08-03 14:04:01

标签: javascript jquery responsive-design

我正在开展一个项目,我的目标是让一个嵌入式iframe的视频播放器在不同屏幕尺寸上观看时能够做出响应。我认为最好的方法是使用调整大小功能。但是,每次在许多不同的配置中,我都尝试使用调整大小功能,它不起作用。我希望每次调整屏幕大小后,文本都会记录到控制台,但是当屏幕加载时,它根本不会被记录,也不会再记录一次。

为什么会这样。

我知道我的jQuery是正确的,因为我在不同的函数中记录其他东西(比如宽度和高度)。

            window.onload = function() {
                $(document).ready(function(){
                    console.log(' <-GoT Here. You FOOL!');

                    var iframe = $('iframe');
                    var videoplayerW = iframe.width(); //640
                    var videoplayerH = $('iframe').height(); //150
                    console.log(videoplayerW, videoplayerH, ' <-This The width and height of iframe.'); //560 and 315


                    var ytplayer = $('#ytplayer');
                    console.log(ytplayer.width(), ytplayer.height(), ' <-This is the ytplayer demonsions'); //undefined

                    iframe.each(function(){
                        $(this)
                            .attr('style', this.height, this.width)
                            .removeAttr('height')
                            .removeAttr('width');
                    });

                    console.log(iframe.width());

                });

            }       

            $(document).ready(function(){
                $(window).resize(function(){
                    console.log('Should have a bunch of numbers');
                });
            });

0 个答案:

没有答案
相关问题