Get css mediaquery breakpoint using js
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 - 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);
Developer | Tomoyuki Kashiro |
Username | Tkashiro |
Uploaded | January 19, 2023 |
Rating | 3 |
Size | 2,502 Kb |
Views | 8,096 |
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!
Name | Size |
Centering Background Video | 4,087 Kb |
3 lines menu button | 3,564 Kb |
Linear search algorithm in JavaScript | 1,698 Kb |
Page transition | 2,767 Kb |
Hashing search algorithm in JavaScript | 1,891 Kb |
CSS Animation Sample | 2,896 Kb |
Shadow Dom Test | 2,204 Kb |
Responsive video | 2,113 Kb |
CSS multi-column layout | 2,627 Kb |
Mostly fluid | 2,386 Kb |
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!
Name | Username | Size |
Twitch | SarahDunlap | 2,937 Kb |
Cloudy Spiral CSS animation | Hakimel | 6,587 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
A Pen by Kevin | Kevinkenger | 2,642 Kb |
Medium Menu | Lucasmotta | 3,923 Kb |
WRENCH - STAFF | Lolita-adams | 1,608 Kb |
The Rope | Chribbe | 2,886 Kb |
We Simplify animation | Meodai | 48,169 Kb |
3D-box | Parthviroja | 2,346 Kb |
Next Word Predictor | Rfalor | 2,776 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!