jQuery根据窗口宽度设置值

时间:2013-04-09 12:16:17

标签: jquery window width

首先;我是一个大jQuery / Javascript新手。 我正在制作一个包含SlidesJS滑块的响应式网站。 我的根本问题是我想根据窗口宽度改变滑块的高度:

如果窗口宽度< 767px将高度设置为600。 否则将高度设置为400。

使用此jQuery代码设置SlidesJS值(我希望灵活的高度):

$(function() {
$('#slides').slidesjs({
width: 940,
height: 400,
play: {
active: true,
auto: true,
interval: 4000,
swap: true
}
});
});

1 个答案:

答案 0 :(得分:1)

这应该有效

$(function() {
    $('#slides').slidesjs({
        width: 940,
        height: setWindowHeight(),
        play: {
            active: true,
            auto: true,
            interval: 4000,
            swap: true
        }
    });
});

function setWindowHeight() {
    return ($(window).width() < 767) ? 600 : 400;   
}