分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

网页响应式媒体查询代码

发布时间:2023-09-06 02:13责任编辑:熊小新关键词:暂无标签

原生实现rem响应式

<!DOCTYPE html><html style="font-size: 100px"><head lang="en"> ???<meta charset="UTF-8"> ???<meta name="viewport" ?????????content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/> ???<title></title> ???<script> ???????/*让文字和标签的大小随着屏幕的尺寸做变话 等比缩放*/ ???????var html = document.getElementsByTagName(‘html‘)[0]; ???????console.log(html); ???????/*取到屏幕的宽度*/ ???????var width = window.innerWidth; ???????console.log(width); ???????/* 640 100 ?320 50 */ ???????var fontSize = 100/640*width; ???????????????console.log(fontSize); ???????/*设置fontsize*/ ???????html.style.fontSize = fontSize +‘px‘; ???????window.onresize = function(){ ???????????var html = document.getElementsByTagName(‘html‘)[0]; ???????????console.log(html); ???????????/*取到屏幕的宽度*/ ???????????var width = window.innerWidth; ???????????console.log(width); ???????????/* 640 100 ?320 50 */ ???????????var fontSize = 100/640 * width; ???????????console.log(fontSize); ???????????/*设置fontsize*/ ???????????html.style.fontSize = fontSize +‘px‘; ???????} ???</script> ???<style> ???????body,html{ ???????????margin: 0; ???????????padding : 0; ???????} ???????div{ ???????????width: 5.28rem; ???????????height: 1rem; ???????????background: red; ???????????color: #fff; ???????????font-size: 0.16rem; ???????} ???</style></head><body> ???<div>AAA</div></body></html>

jq实现rem响应式

$(function(){ ???$(window).on(‘resize‘,function(){ ???????var width=$(window).width(); ???????var fontSize=(width/640)*100; ???????$(‘html‘).css(‘font-size‘,fontSize) ???}).trigger(‘resize‘)})

网页响应式媒体查询代码

原文地址:https://www.cnblogs.com/zbx-boke/p/9571721.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved