Jquery matchMedia max-width不起作用

时间:2015-08-11 16:27:07

标签: jquery css

我有一个脚本,当达到最大宽度479px时,绘制线的高度和宽度减小。但是,我无法让它正常工作。现在,脚本甚至没有运行。这是脚本。我添加的功能是if (window.matchMedia('(max-width: 479px)').matches)

    $(window).load(function() {

        if (window.matchMedia('(max-width: 479px)').matches)
{


  setTimeout(function() {
    TweenLite.defaultEase = Linear.easeNone;

    //show the square only once js has run
    //visibility set to hidden in css panel
    TweenLite.set(".square", {
        visibility: "visible"
    });

    var tl = new TimelineLite();
    tl.fromTo(".l1", 2, {
            height: 0
        }, {
            height: 22
        })
        .fromTo(".l2", 3, {
            width: 0,

        }, {
            width:44

        })
        .fromTo(".l3", 2, {
            height: 0
        }, {
            height: 22
        })
        .fromTo(".l4", 3, {
            width: 0
        }, {
            width: 44
        })


    tl.timeScale(4) //play faster
 }, 600);
 });


} else {


setTimeout(function() {
    TweenLite.defaultEase = Linear.easeNone;

    //show the square only once js has run
    //visibility set to hidden in css panel
    TweenLite.set(".square", {
        visibility: "visible"
    });

    var tl = new TimelineLite();
    tl.fromTo(".l1", 2, {
            height: 0
        }, {
            height: 227
        })
        .fromTo(".l2", 3, {
            width: 0,

        }, {
            width:445

        })
        .fromTo(".l3", 2, {
            height: 0
        }, {
            height: 227
        })
        .fromTo(".l4", 3, {
            width: 0
        }, {
            width: 445
        })


    tl.timeScale(4) //play faster
}, 600);
});

0 个答案:

没有答案