如果窗口小于(),更改CSS类 [英] Change CSS class if window is less than ()

查看:87
本文介绍了如果窗口小于(),更改CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果浏览器窗口小于600像素时,如何更改CSS类的属性。默认属性如下:

How to change a properties of a CSS class in case when browser window is shorter than 600px. Default properties are following:

.side { height:400px; width:700px; }

我想将其更改为:

.side { height:300px; width:550px; }

当窗口高度小于600像素时。

when the window height is less than 600px.

感谢。

推荐答案

您可以尝试:

(function($) {

    var $sides = $('.side');

    var setCss = function() {
        if($(window).height() > 600) {
            $sides.css('width', 400).css('height', 700);
        } else {
            $sides.css('width', 300).css('height', 550);
        }
    };

    $(document).ready(function() {
        setCss();
        $(window).resize(setCss);
    );

})(jQuery);

这篇关于如果窗口小于(),更改CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆