Introduction
In this tutorial, we'll explore the technical aspects of foldable smartphone displays and how to simulate their behavior using modern web technologies. The Oppo Find N6's innovative book-style folding design represents a significant leap in mobile hardware, but we can experiment with similar concepts using HTML, CSS, and JavaScript. This hands-on project will teach you how to create a responsive foldable display simulation that mimics the behavior of modern folding phones.
Prerequisites
Before starting this tutorial, you should have:
- Basic understanding of HTML, CSS, and JavaScript
- Modern web browser (Chrome, Firefox, or Edge)
- Code editor (VS Code recommended)
- Familiarity with CSS flexbox and grid layouts
- Understanding of CSS media queries
Step 1: Setting Up the HTML Structure
We'll begin by creating the basic HTML structure that represents a foldable phone interface. This will include two main sections that will simulate the outer and inner displays of a folding device.
Step 1.1: Create the main container
First, create an HTML file with the basic structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Foldable Display Simulator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="phone-container" id="phoneContainer">
<div class="outer-display" id="outerDisplay">
<div class="status-bar">
<span>9:41</span>
<span>📶 100%</span>
</div>
<div class="app-grid">
<div class="app">📱</div>
<div class="app">📷</div>
<div class="app">🎵</div>
<div class="app">✉️</div>
</div>
</div>
<div class="inner-display" id="innerDisplay">
<div class="inner-status-bar">
<span>Inner Display</span>
</div>
<div class="content-area">
<h2>Foldable Phone Simulation</h2>
<p>This interface demonstrates how content adapts between outer and inner displays.</p>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Step 2: Creating the CSS Styles
Now we'll implement the visual styling that creates the foldable phone effect. The key is to use CSS transforms to simulate the folding mechanism and create responsive layouts.
Step 2.1: Basic phone container styling
First, create the main phone container with a realistic shape:
.phone-container {
width: 360px;
height: 720px;
background: #000;
border-radius: 40px;
padding: 10px;
margin: 50px auto;
position: relative;
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
transition: all 0.5s ease;
}
.outer-display, .inner-display {
width: 100%;
height: 50%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 30px;
padding: 20px;
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
transition: all 0.5s ease;
}
.inner-display {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
Step 2.2: Implementing the folding animation
Next, we'll add the CSS to create the folding effect:
.phone-container.folding {
transform: rotateY(180deg);
transform-style: preserve-3d;
}
.outer-display {
transform-origin: bottom;
transform: rotateX(0deg);
}
.inner-display {
transform-origin: top;
transform: rotateX(0deg);
}
.phone-container.folding .outer-display {
transform: rotateX(-90deg);
}
.phone-container.folding .inner-display {
transform: rotateX(90deg);
}
Step 3: Adding Interactive JavaScript Functionality
The JavaScript will handle the folding animation and content switching between displays.
Step 3.1: Implementing the fold toggle functionality
Create a script that allows users to simulate folding and unfolding:
document.addEventListener('DOMContentLoaded', function() {
const phoneContainer = document.getElementById('phoneContainer');
const outerDisplay = document.getElementById('outerDisplay');
const innerDisplay = document.getElementById('innerDisplay');
// Toggle fold state
phoneContainer.addEventListener('click', function() {
this.classList.toggle('folding');
// Update button text
const button = document.getElementById('foldButton');
if (this.classList.contains('folding')) {
button.textContent = 'Unfold';
} else {
button.textContent = 'Fold';
}
});
// Add responsive behavior
function handleResize() {
if (window.innerWidth < 480) {
phoneContainer.style.width = '320px';
phoneContainer.style.height = '640px';
}
}
window.addEventListener('resize', handleResize);
handleResize();
});
Step 3.2: Adding content switching behavior
Enhance the functionality to show different content on each display:
function switchContent() {
const outerContent = [
'📱 Phone App',
'📷 Camera App',
'🎵 Music Player',
'✉️ Messages'
];
const innerContent = [
'📱 Contacts',
'📷 Gallery',
'🎵 Playlist',
'✉️ Email'
];
const appGrid = document.querySelector('.app-grid');
const contentArea = document.querySelector('.content-area');
if (phoneContainer.classList.contains('folding')) {
// Show inner content
contentArea.innerHTML = 'Inner Display Content
This is the expanded view of the inner display with more detailed information.
Content adapts to the larger screen real estate.
';
} else {
// Show outer content
contentArea.innerHTML = 'Outer Display Content
This is the compact view of the outer display with quick access options.
Content is optimized for smaller screens.
';
}
}
Step 4: Enhancing User Experience
Let's add some advanced features to make our simulation more realistic.
Step 4.1: Adding device orientation detection
Modern foldable phones detect orientation changes, so let's simulate this:
function handleOrientationChange() {
const orientation = window.innerWidth > window.innerHeight ? 'landscape' : 'portrait';
if (orientation === 'landscape') {
phoneContainer.style.width = '720px';
phoneContainer.style.height = '360px';
phoneContainer.classList.add('landscape');
} else {
phoneContainer.style.width = '360px';
phoneContainer.style.height = '720px';
phoneContainer.classList.remove('landscape');
}
}
window.addEventListener('orientationchange', handleOrientationChange);
window.addEventListener('resize', handleOrientationChange);
handleOrientationChange();
Step 4.2: Adding realistic status bar behavior
Simulate the dynamic status bar that changes based on the display state:
function updateStatusBar() {
const statusBar = document.querySelector('.status-bar');
const innerStatusBar = document.querySelector('.inner-status-bar');
if (phoneContainer.classList.contains('folding')) {
innerStatusBar.textContent = 'Inner Display - Expanded View';
statusBar.textContent = 'Outer Display - Compact View';
} else {
innerStatusBar.textContent = 'Inner Display';
statusBar.textContent = 'Outer Display';
}
}
Summary
In this tutorial, we've built a comprehensive foldable phone simulator that demonstrates the core concepts behind modern folding devices like the Oppo Find N6. We've created a responsive interface with:
- Realistic phone container with rounded edges
- Interactive folding animation using CSS 3D transforms
- Responsive design that adapts to different screen sizes
- Content switching between outer and inner displays
- Orientation detection for realistic behavior
This simulation showcases how foldable phones like the Oppo Find N6 can provide different user experiences on each screen surface. The key technical concepts include CSS transforms for 3D effects, media queries for responsive design, and JavaScript event handling for interactive elements. While we've created a web-based simulation, the underlying principles are directly applicable to actual foldable device development, where developers must consider how content adapts to different screen sizes and orientations.



