手机端适配
手机根据相应的屏幕大小 使用不同的font-size
(function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
手机端弹窗
//HTML
<div class="tips" style="display: none">
<div></div>
</div>
// CSS
.tips {
position: fixed;
top: 42%;
100%;
left: 50%;
text-align: center;
z-index: 999;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.tips>div {
display: inline-block;
margin: 0;
padding: 0.2rem 0.3rem;
text-align: center;
color: #fff;
font-size: 0.6rem;
text-shadow: 1px 1px 1px #000;
border-radius: 50px;
/*line-height: 1.5rem;*/
background: rgba(0,0,0,.8);
}
// JS
function showTips(text) {
$('.tips>div').text(text).parent().fadeIn().fadeOut(2000);
}