使用jQuery和CSS进行响应式设计
我有一个网站,通过jQuery为元素设置动画。我的问题是,如果有人用iPad访问你,你是否可以调用特定的函数文件以获得给定的分辨率。在我的脑海中,我尝试过,但不管显示器的大小,都会改变整个页面的功能使用jQuery和CSS进行响应式设计,jquery,jquery-animate,responsive-design,Jquery,Jquery Animate,Responsive Design,我有一个网站,通过jQuery为元素设置动画。我的问题是,如果有人用iPad访问你,你是否可以调用特定的函数文件以获得给定的分辨率。在我的脑海中,我尝试过,但不管显示器的大小,都会改变整个页面的功能 <link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
一般功能
<script type="text/javascript" src="js/funcionesSobre.js"></script>
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
具体功能
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
您可以通过jQuery调整设计,还是只能通过CSS进行调整?Response JS可能适合您的需要
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
有
matchMedia
和MediaQueryList
界面:
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
var mql = window.matchMedia('(min-width:769px)');
// window.matchMedia returns a MediaQueryList object
mql.matches // returns true if the document currently matches the mediaQuery
if(mql.matches) {
// viewport is at least 769px
}
else {
// viewport is 768px max
}
也可以将侦听器添加到MediaQueryList对象:
<link rel="stylesheet" type="text/css" href="css/iPadPortrait.css" media="only screen and (max-width : 768px) and (orientation : portrait)" />
<script type="text/javascript" src="js/funcionesPortrait.js" media="only screen and (max-width : 768px) and (orientation : portrait)"></script>
var media = window.matchMedia('(max-width:400px)');
media.addListener(handleMediaChange);
function handleMediaChange(mql) {
if(mql.matches) {
// viewport is 400px max
}
else {
// viewport is 401px or more
}
}
兼容性
- 铬9+
- 火狐6+
- 狩猎5.1+
- 歌剧12.1+
- Internet Explorer 10+
- Safari Mobile 5+
- 安卓3+
- 有关MDN文档,请参阅和
- 请参阅以获取多边形填充
- 有关兼容性表,请参阅