Get css mediaquery breakpoint using js

Size
2,502 Kb
Views
8,096

How do I make an get css mediaquery breakpoint using js?

What is a get css mediaquery breakpoint using js? How do you make a get css mediaquery breakpoint using js? This script and codes were developed by Tomoyuki Kashiro on 19 January 2023, Thursday.

Get css mediaquery breakpoint using js Previews

Get css mediaquery breakpoint using js - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>get css mediaquery breakpoint using js</title> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Get css mediaquery breakpoint using javascript.</h1>
<div class="main"> <h2 id="target"></h2> <p>resize me. smaller than 400px => mobile</p>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Get css mediaquery breakpoint using js - Script Codes CSS Codes

html, body { width: 100%; height: 100%; position: relative;
}
.main { width: 400px; height: 100px; position: absolute; margin: auto; top: 0; left: 0; right: 0; bottom: 0; text-align: center;
}
h1 { position: absolute; top: 0; left: 0; font-size: 2rem;
}
#target { font-size: 5rem; margin-bottom: 20px;
}
@media screen and (min-width: 400px) { body:after { content: 'desktop'; display: none; }
}

Get css mediaquery breakpoint using js - Script Codes JS Codes

window.isSp = false;
function getDeviceStr() { var str = window.getComputedStyle(document.body,':after').getPropertyValue('content'); window.isSp = str !== 'desktop';
}
function update(){ var str = window.isSp ? 'Mobile' : 'Desktop'; target.innerText = str; requestAnimationFrame(update);
}
// -------------------------------
// main
// -------------------------------
window.addEventListener('resize', _.throttle(getDeviceStr, 500, true), true);
document.addEventListener('DOMContentLoaded', function(){ var target = document.querySelector('#target'); requestAnimationFrame(update);
}, true);
Get css mediaquery breakpoint using js - Script Codes
Get css mediaquery breakpoint using js - Script Codes
Home Page Home
Developer Tomoyuki Kashiro
Username Tkashiro
Uploaded January 19, 2023
Rating 3
Size 2,502 Kb
Views 8,096
Do you need developer help for Get css mediaquery breakpoint using js?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tomoyuki Kashiro (Tkashiro) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!