المكوّنات · شريط يتقلّص مع التمرير
شريط يتقلّص مع التمرير
يبدأ عاليًا ثم ينكمش، ويستعيد ارتفاعه عند العودة للأعلى
12 تصاميم من هذه العائلة
<div class="nb nbk">
<header>
<span class="brand"><span class="mk">▤</span><span data-ar="جريدة الميدان" data-en="Al-Maydan">جريدة الميدان</span></span>
<nav aria-label="الأقسام">
<a href="#" aria-current="page" data-ar="محليات" data-en="Local">محليات</a><a href="#" data-ar="اقتصاد" data-en="Economy">اقتصاد</a><a href="#" data-ar="رياضة" data-en="Sport">رياضة</a><a href="#" data-ar="رأي" data-en="Opinion">رأي</a>
</nav>
<span class="grow"></span>
<span class="date"></span>
</header>
<div class="scr">
<p data-ar="مرّر داخل هذا الصندوق لترى الشريط ينكمش." data-en="Scroll inside this box to see the bar shrink.">مرّر داخل هذا الصندوق لترى الشريط ينكمش.</p>
<div class="filler"></div>
</div>
</div>
/* pt-scoped */
/* navbar-shrink — صحيفة · 64px */
.nbk{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;position:relative}
.nbk header{flex:none;display:flex;align-items:center;gap:9px;width:100%}
.nbk .brand{display:flex;align-items:center;gap:6px;font-weight:700;
color:var(--pt-text-primary);white-space:nowrap}
.nbk .brand .mk{display:grid;place-items:center;flex:none;font-size:10px}
.nbk nav{display:flex;align-items:center;gap:2px;min-width:0}
.nbk nav a{padding:5px 8px;color:var(--pt-text-muted);white-space:nowrap;cursor:pointer;
transition:color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
background var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.nbk nav a:hover{color:var(--pt-text-primary)}
.nbk .grow{flex:1}
.nbk .stage{flex:1;display:flex;flex-direction:column;gap:5px;padding:10px;min-height:0}
.nbk .stage h4{margin:0;font-size:10.5px;color:var(--pt-text-primary)}
.nbk .stage p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.8}
.nbk button{font:inherit;cursor:pointer}
.nbk a:focus-visible, .nbk button:focus-visible, .nbk input:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:-1px}
.nbk header{height:64px;padding:0 12px;background:var(--pt-surface);
border-bottom:1px solid var(--pt-border-subtle);
transition:height var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
.nbk.small header{height:38px}
.nbk .brand{font-size:12.5px;
transition:font-size var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
.nbk.small .brand{font-size:10px}
.nbk .brand .mk{width:20px;height:20px;color:var(--pt-accent);font-size:13px}
.nbk nav{margin-inline-start:10px}
.nbk nav a{border-radius:0;border-bottom:2px solid transparent;padding:3px 7px}
.nbk nav a[aria-current=page]{color:var(--pt-accent);border-bottom-color:var(--pt-accent)}
.nbk .date{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums}
.nbk.small .date{display:none}
.nbk .scr{flex:1;overflow-y:auto;padding:10px}
.nbk .scr p{margin:0 0 8px;font-size:9px;color:var(--pt-text-muted)}
.nbk .filler{height:280px;border-radius:var(--pt-radius-md);
background:repeating-linear-gradient(180deg,var(--pt-bg-inset) 0 14px,transparent 14px 28px)}
@media(prefers-reduced-motion:reduce){.nbk header, .nbk .brand{transition:none}
}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.nbk');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
/* تفعيل الرابط الحالي — سلوك مشترك بين كل الأشرطة */
var links = [].slice.call(root.querySelectorAll('nav a'));
links.forEach(function (a) {
a.addEventListener('click', function (e) {
e.preventDefault();
links.forEach(function (x) { x.removeAttribute('aria-current'); });
a.setAttribute('aria-current', 'page');
});
});
/* إغلاق أي قائمة مفتوحة بالهروب أو بالضغط خارجها */
function autoClose(btn, panel, onToggle) {
function set(v) {
panel.hidden = !v;
btn.setAttribute('aria-expanded', String(v));
if (onToggle) onToggle(v);
}
btn.addEventListener('click', function (e) { e.stopPropagation(); set(panel.hidden); });
panel.addEventListener('click', function (e) { e.stopPropagation(); });
document.addEventListener('click', function () { if (!panel.hidden) set(false); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !panel.hidden) { set(false); btn.focus(); }
});
return set;
}
var scr = root.querySelector('.scr');
/* عتبتان لا واحدة: بعتبة واحدة يتذبذب الشريط عند الحدّ ويرتجف */
var ON = 40, OFF = 16;
scr.addEventListener('scroll', function () {
var y = scr.scrollTop;
if (!root.classList.contains('small') && y > ON) root.classList.add('small');
else if (root.classList.contains('small') && y < OFF) root.classList.remove('small');
}, { passive: true });
root.querySelector('.date').textContent =
new Date().toLocaleDateString('ar-SA-u-nu-latn', { day: 'numeric', month: 'long' });
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Shrinking Navbar
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Shrinking Navbar — Starts tall, shrinks on scroll, and restores at the top
**Why this component matters:** Shrink on scroll must use a threshold with hysteresis, or the bar oscillates between states at the boundary and flickers under the reader.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.