<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>小説投稿サイト</title>
<style>
body {
font-family: sans-serif;
padding: 20px;
max-width: 800px;
margin: auto;
background: #f2f2f2;
}
h1 {
text-align: center;
}
form {
background: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input, textarea {
width: 100%;
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.post {
background: white;
padding: 15px;
border-left: 5px solid #007bff;
margin-bottom: 20px;
border-radius: 5px;
}
.post h2 {
margin: 0 0 10px;
}
.meta {
color: gray;
font-size: 0.9em;
margin-bottom: 10px;
}
.delete-btn {
background-color: #dc3545;
color: white;
border: none;
padding: 5px 10px;
border-radius: 4px;
float: right;
cursor: pointer;
}
</style>
</head>
<body>
<h1>小説投稿サイト</h1>
<form id="novelForm">
<input type="text" id="author" placeholder="著者名" required>
<input type="text" id="title" placeholder="タイトル" required>
<textarea id="content" rows="8" placeholder="本文" required></textarea>
<button type="submit">投稿する</button>
</form>
<div id="postList"></div>
<script>
const form = document.getElementById('novelForm');
const postList = document.getElementById('postList');
let posts = JSON.parse(localStorage.getItem('novels')) || [];
function saveAndRender() {
localStorage.setItem('novels', JSON.stringify(posts));
renderPosts();
}
function renderPosts() {
postList.innerHTML = '';
[...posts].reverse().forEach((post, index) => {
const div = document.createElement('div');
div.className = 'post';
div.innerHTML = `
<button class="delete-btn" onclick="deletePost(${index})">削除</button>
<h2>${post.title}</h2>
<div class="meta">著者: ${post.author} | 投稿日: ${post.date}</div>
<p>${post.content.replace(/\n/g, '<br>')}</p>
`;
postList.appendChild(div);
});
}
form.addEventListener('submit', e => {
e.preventDefault();
const title = document.getElementById('title').value;
const content = document.getElementById('content').value;
const author = document.getElementById('author').value;
const date = new Date().toLocaleString();
posts.push({ title, content, author, date });
form.reset();
saveAndRender();
});
window.deletePost = function(index) {
posts.splice(posts.length - 1 - index, 1); // reverseしてるため
saveAndRender();
}
renderPosts();
</script>
</body>
</html>
カテゴリー: programming
MySQL IF CASE
DROP TABLE IF EXISTS posts;
CREATE TABLE posts (
id INT NOT NULL AUTO_INCREMENT,
message VARCHAR(140),
likes INT,
area VARCHAR(20),
PRIMARY KEY (id)
);
INSERT INTO posts (message, likes, area) VALUES
('post-1', 12, 'Tokyo'),
('post-2', 8, 'Fukuoka'),
('post-3', 11, 'Tokyo'),
('post-4', 3, 'Osaka'),
('post-5', 8, 'Tokyo'),
('post-6', 9, 'Osaka'),
('post-7', 4, 'Tokyo'),
('post-8', 10, 'Osaka'),
('post-9', 31, 'Fukuoka');
CSS メディアクエリー
style.css
@charset "utf-8";
.card {
border: 1px solid #ccc;
box-sizing: border-box;
padding: 16px;
max-width: 600px;
margin: 0 auto;
&:hover {
box-shadow: 0 0 8px rgb(0 0 0 / 0.3);
}
h2 {
margin: 0;
border-bottom: 1px solid #ccc;
text-align: center;
font-size: 18px;
padding-bottom: 8px;
}
p {
margin: 16px 0 0;
line-height: 1.6;
}
}
@media (width >=600px) {
.card h2 {
text-align: left;
}
}
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My CSS Nesting</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section class="card">
<h2>こんにちは</h2>
<p>こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。</p>
</section>
</body>
</html>
企画書:Windows 12
企画書:Windows 12
1. 概要
- プロジェクト名: Windows 12 開発プロジェクト
- 提案者: (あなたのチーム/部署名などを記載)
- 目的: Windows 11 の次世代OSとして、UI・UX・クラウド連携・セキュリティのさらなる強化を図り、ユーザーに安全かつ便利なコンピューティング環境を提供する。
2. 背景・課題
- Windows 11 の普及とユーザーニーズ
- Windows 11 は現行OSとして機能しているが、新しい体験やさらなる改良を望む声がある。
- タッチ操作・音声操作などマルチインターフェースへの最適化が進む中、UI改善と生産性向上の両立が課題。
- クラウド連携の需要増加
- 在宅勤務やリモート学習の定着で、クラウドストレージ、オンラインコラボレーションツールへの需要が急増。
- Microsoft 365 やAzure など、自社クラウドサービスとのさらなる連携が必要。
- セキュリティ強化
- ランサムウェア、標的型攻撃などサイバー脅威が高度化。
- OSレベルでのゼロトラストセキュリティ対策や暗号化技術、マルチ要素認証との連携強化が必須。
- AIアシスタントとの統合
- MicrosoftのAI技術(例: Cortana / Bing Chat / その他LLMなど)をよりOSレベルに深く取り込み、ユーザー体験を向上させるニーズがある。
3. 目的・ゴール
- UI/UX の再定義: 直感的で分かりやすく、アプリやクラウドサービスとの親和性を高めた新UIの提供。
- 生産性向上: 作業効率を支援する機能(ウィンドウの整理、アプリ間連携、自動翻訳など)を強化。
- 高いセキュリティ: OSレベルのセキュリティ機能を強化し、企業や個人が安心して利用できるプラットフォームを実現。
- クラウド連携強化: OneDrive や SharePoint をさらに活用し、ストレージや共同作業をOS標準機能としてシームレスに統合。
- AIアシスタントの活用: Windowsシステム全体を横断してタスクを支援するAI機能を実装し、スマートな作業環境を提供。
4. ターゲットユーザー
- ビジネスユーザー
- リモートワークやハイブリッドワークの運用が多い企業やフリーランス。
- セキュリティや生産性に強いOSを求める法人顧客。
- コンシューマー(一般ユーザー)
- 最新の機能やUI/UXを快適に使いたい個人。
- PC初心者から上級者まで幅広い層。
- 教育機関
- オンライン学習や共同作業プラットフォームを活用する学校・大学。
- セキュリティや遠隔操作管理の機能が求められる。
5. 特徴・機能
- 新デザインUI「Fluent Next」
- ウィンドウ操作、通知センター、スタートメニューの刷新。
- アクセシビリティを強化し、より柔軟でモダンなデザイン。
- クラウド連携の強化
- OSレベルで OneDrive や Teams が組み込まれ、ファイル共有・共同編集がシームレスに。
- ストレージ残容量やファイル更新情報をリアルタイムで通知。
- Windows Copilot(AIアシスタント)の進化
- 音声入力やチャット操作など、各シーンに応じてマルチタスクを支援。
- 自動サマリー作成やメール下書きなどをサポート。
- セキュリティ / ゼロトラスト対応
- TPM 2.0 を活用したハードウェアレベルの暗号化と認証強化。
- フィッシング防止やマルウェア対策をさらに高度化。
- 企業向けにはクラウドポリシーと連携し、認証管理を一元化。
- パフォーマンス最適化 / 省電力
- OSカーネルと電源管理の改善により、省電力モード時のバッテリー持続時間を向上。
- ゲーミングモードやクリエイティブモードなど、状況に応じたリソース割り当てを自動調整。
- 拡張ディスプレイ & マルチデバイス対応
- タブレットや折りたたみ型PCなど、画面サイズが変化するデバイスでの最適化。
- スマホとの連携強化(電話・メッセージ通知、写真自動同期など)。
6. 開発スケジュール(例)
フェーズ | 期間 | 主なタスク |
---|---|---|
要件定義 | 20XX年 Q1~Q2 | UIデザイン要件決定、主要機能の企画設計 |
開発・実装 | 20XX年 Q3~20XY年Q1 | コア機能実装、セキュリティ強化 内部テスト |
パブリックβ版 | 20XY年 Q2 | パブリックベータテスト 外部フィードバック回収 |
正式リリース | 20XY年 Q3 | 最終調整・品質保証 グローバルローンチ |
7. 予算・リソース
- 人件費: エンジニア、UI/UXデザイナー、QA、プロジェクトマネージャーなど。
- インフラ費: クラウドサーバー、CI/CD環境、テスト機材購入など。
- マーケティング費: リリース前後の広告宣伝費、イベント開催費など。
- 合計予算の目安: (現実的には大きな額になりますが、具体的な金額はプロジェクト規模に依存)
8. 成功指標 (KPI)
- アップグレード率: 既存ユーザーからの移行数、Windows 10/11ユーザーのアップデート率。
- エラー/クラッシュレポートの減少率: OSの安定性・信頼性を継続してモニタリング。
- クラウドサービス利用率: OneDrive / Teams などの利用継続率、導入企業数。
- ユーザー満足度: フィードバックやアンケートによるNPS(ネット・プロモーター・スコア)など。
9. リスクと対策
- 既存アプリ互換性
- 過去OS向けアプリが動作しない問題。
- → 互換レイヤーや仮想化技術を提供し、互換性向上に注力。
- 大規模なUI変更に対する反発
- → カスタマイズ性を高め、ユーザーが旧UIレイアウトへ切り替え可能なモードを検討。
- セキュリティ脆弱性
- → リリース前のセキュリティ監査を強化し、定期的に更新プログラムを配信。
10. まとめ
- Windows 12 は 「セキュリティ強化」「UI/UX革新」「AI活用」「クラウド統合」 を核とした次世代OSとなる。
- 企業・教育機関・一般ユーザーなど幅広い層に向けて、安全かつ効率的な作業環境 を提供することをゴールとする。
- 今後は段階的に開発と検証を進め、ユーザーからのフィードバックを取り込みながら 正式リリース を目指す。
Vooglebrowser
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Voogleブラウザ</title>
<meta property="og:title" content="Voogleブラウザ">
<meta property="og:description" content="次世代タブブラウザ Voogle">
<meta property="og:url" content="https://voogle.onrender.com/">
<meta property="og:type" content="website">
<meta property="og:image" content="https://voogle.onrender.com/ogp.png">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
body.dark {
background-color: #222;
color: #fff;
}
header {
background-color: #4285F4;
padding: 15px;
color: white;
font-size: 24px;
text-align: center;
}
#tabs {
display: flex;
background-color: #e0e0e0;
padding: 10px;
overflow-x: auto;
}
.tab {
padding: 8px 16px;
background-color: white;
border-radius: 20px;
margin-right: 10px;
cursor: grab;
font-weight: bold;
position: relative;
user-select: none;
}
.tab.active {
background-color: #34A853;
color: white;
}
.tab .close {
position: absolute;
top: 0;
right: 5px;
cursor: pointer;
font-family: 'Material Icons';
}
#navbar {
display: flex;
padding: 10px;
background-color: #f1f1f1;
gap: 10px;
}
#url {
flex: 1;
padding: 10px;
border-radius: 20px;
border: 1px solid #ccc;
}
button {
padding: 10px 20px;
background-color: #4285F4;
color: white;
border: none;
border-radius: 20px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
}
#spinner {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 24px;
}
iframe {
width: 100%;
height: calc(100% - 240px);
border: none;
}
footer {
padding: 10px;
background-color: #e0e0e0;
text-align: center;
font-size: 12px;
}
</style>
</head>
<body>
<header>
<span class="material-icons" style="vertical-align: middle; margin-right: 10px;">language</span>
<a href="https://voogle.onrender.com/">Voogleブラウザ</a>
</header>
<div id="tabs"></div>
<div id="navbar">
<input type="text" id="url" placeholder="https://example.com">
<button id="go"><span class="material-icons">arrow_forward</span>移動</button>
<button id="newTab"><span class="material-icons">add</span>タブ追加</button>
<button id="darkModeToggle"><span class="material-icons">dark_mode</span>ダークモード</button>
</div>
<div id="spinner">読み込み中...</div>
<iframe id="viewer"></iframe>
<footer>
© 2025 Voogle Inc.
</footer>
<script>
const tabs = document.getElementById('tabs');
const viewer = document.getElementById('viewer');
const urlInput = document.getElementById('url');
const goButton = document.getElementById('go');
const newTabButton = document.getElementById('newTab');
const darkModeToggle = document.getElementById('darkModeToggle');
const spinner = document.getElementById('spinner');
let tabData = [];
let activeTab = -1;
function switchTab(index) {
activeTab = index;
document.querySelectorAll('.tab').forEach((tab, i) => {
tab.classList.toggle('active', i === index);
});
loadPage(tabData[index].url);
}
function addTab(url = 'https://voogle.onrender.com/') {
tabData.push({ url });
const index = tabData.length - 1;
const tab = document.createElement('div');
tab.className = 'tab';
tab.setAttribute('draggable', true);
tab.innerHTML = `タブ ${index + 1} <span class="close">close</span>`;
tab.onclick = () => switchTab(index);
tab.querySelector('.close').onclick = (e) => {
e.stopPropagation();
tabs.removeChild(tab);
tabData.splice(index, 1);
if (activeTab === index) {
viewer.src = '';
urlInput.value = '';
}
};
tabs.appendChild(tab);
switchTab(index);
}
function loadPage(url) {
spinner.style.display = 'block';
viewer.src = url;
urlInput.value = url;
viewer.onload = () => {
spinner.style.display = 'none';
document.title = viewer.contentDocument.title || 'Voogleブラウザ';
};
}
goButton.onclick = () => {
if (activeTab >= 0) {
let url = urlInput.value.trim();
if (!url.startsWith('http')) {
url = 'https://' + url;
}
tabData[activeTab].url = url;
loadPage(url);
}
};
newTabButton.onclick = () => addTab();
darkModeToggle.onclick = () => {
document.body.classList.toggle('dark');
localStorage.setItem('darkMode', document.body.classList.contains('dark'));
};
if (localStorage.getItem('darkMode') === 'true') {
document.body.classList.add('dark');
}
addTab();
</script>
</body>
</html>
消費型オタクと生産型オタクの違い
消費型オタクと生産型オタクの違いは、趣味への関わり方にあります。
消費型オタク
- 主に 作品を楽しむことが中心 のオタク。
- アニメ、漫画、ゲーム、小説などを 視聴・購読・プレイ して楽しむ。
- グッズやフィギュア、Blu-rayなどを 購入 する。
- SNSや掲示板で 感想を共有 する。
- コスプレやイベント参加など、体験型の楽しみ方をすることも。
例
- アニメをリアルタイムで視聴し、円盤やグッズを買う。
- 推しのキャラクターのフィギュアやタペストリーを集める。
- ゲームをプレイして感想をツイートする。
生産型オタク
- 自ら創作活動を行う オタク。
- イラスト、小説、同人誌、漫画、動画、音楽、ゲーム制作などの 二次創作・オリジナル作品を作る。
- 3Dモデリング、プログラミング、AI技術などを活かして創作することも。
- YouTube、Pixiv、ニコニコ動画、BOOTHなどで 作品を発表・販売 する。
例
- 好きなアニメのキャラを描いてSNSに投稿する。
- 同人誌や同人ゲームを作成してイベント(例:コミケ)で頒布する。
- VTuberのLive2Dモデルを作成する。
- AIを使ってオリジナルの物語を生成する。
ハイブリッド型(両方)
最近は、消費しながら創作する ハイブリッド型 のオタクも多いです。
- 最初は消費型→生産型に移行する 例も多い。
- 例:「好きな作品の二次創作イラストを描き始めたら、いつの間にか生産型になっていた」
- 逆に、生産型だけど他の作品も 消費してインスピレーションを得る こともある。
どちらが良い・悪いという話ではない
- 消費型は市場を支える → コンテンツが売れないと創作活動も続かない。
- 生産型は新しいコンテンツを生み出す → 二次創作が原作の人気を支えることも。
- どちらもオタク文化の重要な一部。
結論:「消費型も生産型も、それぞれの楽しみ方がある!」
C# スライムの攻撃
using System;
public class Program{
public static void Main(){
var random = new Random();
var dice = random.Next(1, 7);
Console.WriteLine("サイコロは" + dice);
if (dice >= 4) {
Console.WriteLine("スライムの攻撃をかわした");
} else {
Console.WriteLine("スライムから10のダメージを受けた");
}
}
}
C# if文による条件分岐 比較演算子
// if文による条件分岐 比較演算子
using System;
public class Program{
public static void Main(){
var time = 12;
if(time < 12){
Console.WriteLine("午前中"); // 条件式が成立したときの処理
} else if (time == 12){
Console.WriteLine("正午");
} else if (time > 12){
Console.WriteLine("午後");
}
}
}
ARTBOOK
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ARTBOOK - アートSNS</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f9fafb;
color: #333;
}
header {
background-color: #4a5568;
color: white;
padding: 1.5rem;
text-align: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
header h1 {
margin: 0;
font-size: 2.5rem;
}
header p {
margin: 0.5rem 0;
font-size: 1.2rem;
}
header nav {
margin-top: 1rem;
}
header nav a {
color: white;
text-decoration: none;
margin: 0 1rem;
font-weight: bold;
font-size: 1.1rem;
padding: 0.5rem 1rem;
border-radius: 5px;
transition: background-color 0.3s;
}
header nav a:hover {
background-color: #2d3748;
}
.container {
max-width: 1200px;
margin: 2rem auto;
padding: 1rem;
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
font-weight: bold;
}
.form-group input, .form-group textarea {
width: 100%;
padding: 0.8rem;
border: 1px solid #d2d6dc;
border-radius: 6px;
background-color: #f7fafc;
font-size: 1rem;
}
.form-group button {
background-color: #3182ce;
color: white;
border: none;
padding: 0.8rem 1.5rem;
font-size: 1rem;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s;
}
.form-group button:hover {
background-color: #2b6cb0;
}
.profile {
text-align: center;
}
.profile img {
width: 150px;
height: 150px;
border-radius: 50%;
object-fit: cover;
margin-bottom: 1rem;
}
footer {
text-align: center;
padding: 1.5rem;
background-color: #4a5568;
color: white;
margin-top: 2rem;
}
footer p {
margin: 0;
font-size: 1rem;
}
</style>
</head>
<body>
<header>
<h1>ARTBOOK</h1>
<p>あなたのアートをシェアしよう!</p>
<nav>
<a href="#home" onclick="navigateTo('home')">ホーム</a>
<a href="#gallery" onclick="navigateTo('gallery')">作品一覧</a>
<a href="#post" onclick="navigateTo('post')">投稿する</a>
<a href="#profile" onclick="navigateTo('profile')">プロフィール</a>
</nav>
</header>
<div id="content" class="container">
<!-- コンテンツがここに動的に挿入されます -->
</div>
<footer>
<p>© 2025 ARTBOOK. All Rights Reserved.</p>
</footer>
<script>
let posts = JSON.parse(localStorage.getItem('posts')) || [];
let profile = JSON.parse(localStorage.getItem('profile')) || {
name: "未設定",
bio: "ここに自己紹介が表示されます",
image: "https://via.placeholder.com/150"
};
function navigateTo(section) {
const content = document.getElementById('content');
content.innerHTML = '';
if (section === 'home') {
content.innerHTML = `<h2>ホーム</h2><p>ようこそ、ARTBOOKへ!最新のアート作品をご覧ください。</p>`;
} else if (section === 'gallery') {
content.innerHTML = `<h2>作品一覧</h2><div id='gallery'>${renderPosts()}</div>`;
} else if (section === 'post') {
content.innerHTML = `
<h2>投稿する</h2>
<form id="postForm">
<div class="form-group">
<label for="title">タイトル</label>
<input type="text" id="title" name="title" required>
</div>
<div class="form-group">
<label for="description">説明</label>
<textarea id="description" name="description" rows="4" required></textarea>
</div>
<div class="form-group">
<label for="upload">画像アップロード</label>
<input type="file" id="upload" name="upload" accept="image/*" required>
</div>
<div class="form-group">
<button type="button" onclick="submitPost()">投稿する</button>
</div>
</form>`;
} else if (section === 'profile') {
content.innerHTML = `
<h2>プロフィール</h2>
<div class="profile">
<img src="${profile.image}" alt="プロフィール画像">
<h3>${profile.name}</h3>
<p>${profile.bio}</p>
<form id="profileForm">
<div class="form-group">
<label for="name">名前</label>
<input type="text" id="name" value="${profile.name}" required>
</div>
<div class="form-group">
<label for="bio">自己紹介</label>
<textarea id="bio" rows="4" required>${profile.bio}</textarea>
</div>
<div class="form-group">
<label for="profileImage">プロフィール画像</label>
<input type="file" id="profileImage" accept="image/*">
</div>
<div class="form-group">
<button type="button" onclick="updateProfile()">更新する</button>
</div>
</form>
</div>`;
}
}
function submitPost() {
const title = document.getElementById('title').value;
const description = document.getElementById('description').value;
const upload = document.getElementById('upload').files[0];
if (title && description && upload) {
const reader = new FileReader();
reader.onload = function(event) {
posts.push({ title, description, image: event.target.result });
localStorage.setItem('posts', JSON.stringify(posts));
alert('投稿が完了しました!');
navigateTo('gallery');
};
reader.readAsDataURL(upload);
} else {
alert('すべてのフィールドを入力してください。');
}
}
function updateProfile() {
const name = document.getElementById('name').value;
const bio = document.getElementById('bio').value;
const profileImage = document.getElementById('profileImage').files[0];
if (name && bio) {
if (profileImage) {
const reader = new FileReader();
reader.onload = function(event) {
profile.image = event.target.result;
saveProfile(name, bio);
};
reader.readAsDataURL(profileImage);
} else {
saveProfile(name, bio);
}
} else {
alert('すべてのフィールドを入力してください。');
}
}
function saveProfile(name, bio) {
profile.name = name;
profile.bio = bio;
localStorage.setItem('profile', JSON.stringify(profile));
alert('プロフィールが更新されました!');
navigateTo('profile');
}
function renderPosts() {
if (posts.length === 0) {
return '<p>まだ投稿がありません。</p>';
}
return posts.map(post => `
<div class="art-card">
<img src="${post.image}" alt="${post.title}">
<h2>${post.title}</h2>
<p>${post.description}</p>
</div>`).join('');
}
// 初期表示
navigateTo('home');
</script>
</body>
</html>
MyCarousel
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Carousel</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<section class="carousel">
<div class="container">
<ul>
<li><img src="img/pic1.png"></li>
<li><img src="img/pic2.png"></li>
<li><img src="img/pic3.png"></li>
<li><img src="img/pic4.png"></li>
</ul>
<button id="prev">«</button>
<button id="next">»</button>
</div>
<nav>
</nav>
</section>
<script src="js/main.js"></script>
</body>
</html>
js/main.js
'use strict';
{
const next = document.getElementById('next');
const prev = document.getElementById('prev');
const ul = document.querySelector('ul');
const slides = ul.children;
const dots = [];
let currentIndex = 0;
function updateButtons() {
prev.classList.remove('hidden');
next.classList.remove('hidden');
if (currentIndex === 0) {
prev.classList.add('hidden');
}
if (currentIndex === slides.length - 1) {
next.classList.add('hidden');
}
}
function moveSlides() {
const slideWidth = slides[0].getBoundingClientRect().width;
ul.style.transform = `translateX(${-1 * slideWidth * currentIndex}px)`;
}
function setupDots() {
for (let i = 0; i < slides.length; i++) {
const button = document.createElement('button');
button.addEventListener('click', () => {
currentIndex = i;
updateDots();
updateButtons();
moveSlides();
});
dots.push(button);
document.querySelector('nav').appendChild(button);
}
dots[0].classList.add('current');
}
function updateDots() {
dots.forEach(dot => {
dot.classList.remove('current');
});
dots[currentIndex].classList.add('current');
}
updateButtons();
setupDots();
next.addEventListener('click', () => {
currentIndex++;
updateButtons();
updateDots();
moveSlides();
});
prev.addEventListener('click', () => {
currentIndex--;
updateButtons();
updateDots();
moveSlides();
});
window.addEventListener('resize', () => {
moveSlides();
});
}
css/style.css
.carousel {
width: 80%;
margin: 16px auto;
}
.container {
width: 100%;
height: 220px;
overflow: hidden;
position: relative;
}
ul {
list-style: none;
margin: 0;
padding: 0;
height: 100%;
display: flex;
transition: transform .3s;
}
li {
height: 100%;
min-width: 100%;
}
li img {
width: 100%;
height: 100%;
object-fit: cover;
}
#prev,
#next {
position: absolute;
top: 50%;
transform: translateY(-50%);
border: none;
background: rgba(0, 0, 0, .8);
color: #fff;
font-size: 24px;
padding: 0 8px 4px;
cursor: pointer;
}
#prev:hover,
#next:hover {
opacity: .8;
}
#prev {
left: 0;
}
#next {
right: 0;
}
.hidden {
display: none;
}
nav {
margin-top: 16px;
text-align: center;
}
nav button+button {
margin-left: 8px;
}
nav button {
border: none;
width: 16px;
height: 16px;
background: #ddd;
border-radius: 50%;
cursor: pointer;
}
nav .current {
background: #999;
}