[英]PHP width screen with different display
我有一个要使用jpg + video或jpg显示的背景。 如果是桌面屏幕,则显示jpg +视频,否则,如果iphone或ipad大小,则显示jpg背景。 用PHP编码。 我在想也许可以使用if语句,但是我不确定。 请帮忙!
以下是在台式机/笔记本电脑屏幕上显示的尺寸:
<div id="header-bg">
<video id="video_background" preload="auto" autoplay="true" loop="loop" muted="muted" volumne="0">
<source src="images/show-bg.mp4" type="video/mp4">
<source src="images/show-bg.webm" type="video/webm">
<source src="images/show-bg.ogv" type="video/ogg">
Video not supported
</video>
以下是在iPhone / ipad上显示的尺寸:
<div id="header-bg1">
“ header-bg”和“ header-bg1”链接到CSS。
以下是CSS:
#header-bg {background: url(../images/header/show-bg.png) 0% 0 no-repeat;}
#header-bg1 {background: url(../images/header/show-bg.jpg) 0% 0 no-repeat;}
#video_background {position: absolute; bottom: 0px; right: 0px; min-width: 100%; min-height: 100%; width= auto; height: auto; z-index: -1000; overflow: hidden;}
这不是您应该在服务器(PHP)端上决定的事情。 将modernizr javascript库添加到您的页面并使用其功能检测。
可能需要大量额外的代码来专门针对iPad等,但是此JavaScript可能有效:
<script>
if ( $( window ).width() > 1024 {
document.write("
<div id="header-bg"></div>
<video id="video_background" preload="auto" autoplay="true" loop="loop" muted="muted" volumne="0">
<source src="images/show-bg.mp4" type="video/mp4">
<source src="images/show-bg.webm" type="video/webm">
<source src="images/show-bg.ogv" type="video/ogg">
Video not supported
</video>
");
} else {
document.write("
<div id="header-bg1"></div>
");
}
</script>
如果使用媒体屏幕,则可以在<head>
放置类似的内容。 这将需要单独的样式表或创建一个样式表并使用第二部分:
<head>
<link href="" media="screen and (max-width: 1024px)" rel="stylesheet" type="text/css"> <!-- Should target iPads -->
<link href="" media="screen and (max-width: 480px)" rel="stylesheet" type="text/css"> <!-- Should target iPhones -->
</head>
一个样式表,将其添加到样式表的底部:
@media screen and (max-width: 1024px) {
css goes here {
}
}
@media screen and (max-width: 480px) {
css goes here {
}
}
尝试添加display: none
不希望在移动设备上显示,而不能在PC上显示,反之亦然。 媒体查询也将覆盖您在主CSS中添加的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.