简体   繁体   English

调整浏览器窗口大小的JavaScript功能

[英]JavaScript functionality to browser window resize

I have been writting HTML and CSS for a while but am new to the javascript domain. 我已经写了一段时间的HTML和CSS了,但是对于javascript域却是新手。 I am using the below code to control the attributes of a jQuery slider. 我正在使用下面的代码来控制jQuery滑块的属性。 The code works fine, but what I need to do is change some of the elements within it as the browser screen resizes (or loaded on mobile device) to enable the functionality to work correctly on smaller screens. 该代码可以正常工作,但是我需要做的是随着浏览器屏幕调整大小(或加载到移动设备上)来更改其中的某些元素,以使该功能能够在较小的屏幕上正常工作。

 $(document).ready(
        function() {
            $(".container").wtListRotator({
                screen_width:534,
                screen_height:300,
                item_width:210,
                item_height:75,
                item_display:4,
                list_align:"left",
                scroll_type:"mouse_move",
                auto_start:true,
                delay:5000,
                transition:"v.slide",
                transition_speed:800,
                easing:"",
                auto_center:true,
                display_playbutton:false,
                display_number:false,
                display_timer: false,
                display_arrow:true,
                display_thumbs:true,
                display_scrollbar:true,
                mouseover_select:false,
                pause_mouseover: true,
                cpanel_mouseover:false,                 
                text_mouseover:false,
                text_effect:"fade",
                text_sync:true,
                cpanel_align:"TR",
                timer_align:"bottom",
                move_one:false,
                auto_adjust:true,
                shuffle:false,
                play_once:false,
                mousewheel_scroll:true,                 
                block_size:75,
                vert_size:50,
                horz_size:50,
                block_delay:35,
                vstripe_delay:90,
                hstripe_delay:180                   
            });
        }
    );

I have already implemented media queries on the elements in the CSS so they resize and also across the rest of my site, however I am struggling to change the attributes below when the screen size/re-size event occurs and define this in the above javascript. 我已经在CSS中的元素上实现了媒体查询,因此它们的大小以及整个网站的其余部分都可以调整大小,但是当屏幕大小/调整大小事件发生时,我正在努力更改以下属性,并在上面的javascript中进行定义。

screen_width:534,
                screen_height:300,
                item_width:210,
                item_height:75,
                item_display:4,   

Thanks 谢谢

Rich 丰富

two things that might help you: 有两件事可能对您有帮助:

1) you can always get the current usable width/height of the browser window using window.innerWidth and window.innerHeight . 1)您始终可以使用window.innerWidthwindow.innerHeight获得浏览器窗口的当前可用宽度/高度。

2) you can "register" a function to be called whenever the size of the window changes. 2)每当窗口大小改变时,您都可以“注册”要调用的函数。 Examples: 例子:

window.addEventListener("resize",nameOfFunction);

window.onresize = function() { //do stuff };

I'm happy to help if you have further questions... 如果您还有其他问题,我们很乐意为您提供帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM