简体   繁体   English

Javascript和媒体查询

[英]Javascript and media queries

I want to add some kind of media query to the JS below so on mobile or screens <767px the height only animates to 280px. 我想在下面的JS中添加某种媒体查询,以便在手机或屏幕上<767px的高度仅设置为280px的动画。 Also would be interested if this can be achieved with CSS 如果这可以通过CSS实现也将感兴趣

Javascript Java脚本

   $("#open").click(function(e){
       e.preventDefault();
        $("div#panel").animate({height: "337px"},"medium");
    });

Many thanks 非常感谢

There's a great CSS3 solution that is described in this article: http://webdesignerwall.com/tutorials/adaptive-mobile-design-with-css3-media-queries 本文介绍了一个很棒的CSS3解决方案: http : //webdesignerwall.com/tutorials/adaptive-mobile-design-with-css3-media-queries

This technique uses the CSS media query: @media screen and (max-width: 767px) { ... } 此技术使用CSS媒体查询: @media screen and (max-width: 767px) { ... }

Keep in mind that you might have to get a little creative in your solution if you choose to use this method. 请记住,如果您选择使用此方法,则可能必须在解决方案中有所创新。 Let me know if this is enough information, or if you need me to detail how you could use this to solve your problem. 让我知道这是否足够的信息,或者您是否需要我详细说明如何使用此信息来解决您的问题。

========== Edit ==========编辑

There's probably a much better way to go about this, but here's what I was thinking... 解决这个问题的方法可能更好,但这就是我在想的...

CSS: CSS:

#panel {
  z-index: 0;
}

@media screen and (max-width: 767px) {
  #panel {
    z-index: 1;
  }
}

jQuery: jQuery的:

$("#open").click(function(e){
  e.preventDefault();
  $("div#panel").css("z-index", 0).animate({height: "337px"},"medium");
  $("div#panel").css("z-index", 1).animate({height: "280px"},"medium");
});

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

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