Горизонтальное меню с прокруткой, сделанное на CSS и jQuery

Andris Valums, “Horizontal Scrolling Menu made with CSS and jQuery”, public translation into Russian from English More about this translation.

See also 9 similar translations

Translate into another language.

Participants

MaxPv335 points
stryaponoff191 points
StaSa123 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next
1 2 3

Horizontal Scrolling Menu made with CSS and jQuery

Горизонтальное меню с прокруткой, сделанное на CSS и jQuery

History of edits (Latest: MoLnIyA 1 year, 8 months ago) §

There are a lot of cool flash scrolling menus out there, but I decided to make a similarly looking menu with just CSS and jQuery. I couldn’t achieve the same smoothness in animation, but anyway I’m really satisfied with the result. My menu works fine in all major browsers and degrades gracefully when Javascript is turned off.

Существует довольно много классных меню с прокруткой на Flash, но я решил сделать аналогичное меню, используя только CSS и jQuery. Я не смог достичь той же гладкости в анимации, но все же я очень доволен результатом. Мое меню работает во всех популярных браузерах и изящно исчезает, когда JavaScript отключён.

History of edits (Latest: space_indus 1 year, 9 months ago) §

— не уверен в слове "исчезает". Но "отключается" сюда не очень подходит. space_indus

In case you need a vertical version of a scrolling menu, please go to my newer tutorial.

В случае, если вам понадобится вертикальная версия меню с прокруткой, пожалуйста, обратитесь к моему новому руководству.

History of edits (Latest: mk93 1 year, 9 months ago) §

View the Result

Просмотр результата

History of edits (Latest: MaxPv 2 years, 6 months ago) §

Creating markup

Создание разметки

History of edits (Latest: MaxPv 2 years, 6 months ago) §

Let’s begin by creating the necessary HTML structure. We will use an unordered list with each list item containing an image and a caption. We will also add an additional wrapper element.

Давайте начнем с создания требуемой структуры HTML. Мы будем использовать неупорядоченный список, каждая статья которого содержит картинку и заголовок. Также мы добавим дополнительный внешний контейнер.

History of edits (Latest: mk93 1 year, 9 months ago) §

<div class="sc_menu">

<div class="sc_menu">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<ul class="sc_menu">

<ul class="sc_menu">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<li><a href="#">

<li><a href="#">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<img src="img/1.jpg" alt="Menu"/><span>Menu</span>

<img src="img/1.jpg" alt="Menu"/><span>Menu</span>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</a></li>

</a></li>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<li><a href="#">

<li><a href="#">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<img src="img/2.jpg" alt="Navigation"/><span>Navigation</span>

<img src="img/2.jpg" alt="Navigation"/><span>Navigation</span>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</a></li>

</a></li>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<li><a href="#">

<li><a href="#">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<img src="img/3.jpg" alt="Scrolling"/><span>Scrolling</span>

<img src="img/3.jpg" alt="Scrolling"/><span>Scrolling</span>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</a></li>

</a></li>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<li><a href="#">

<li><a href="#">

History of edits (Latest: MaxPv 2 years, 6 months ago) §

<img src="img/4.jpg" alt="jQuery"/><span>jQuery</span>

<img src="img/4.jpg" alt="jQuery"/><span>jQuery</span>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</a></li>

</a></li>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</ul>

</ul>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

</div>

</div>

History of edits (Latest: MaxPv 2 years, 6 months ago) §

Adding basic styling

Добавление основного стиля

History of edits (Latest: StaSa 2 years, 5 months ago) §

Now we need to add some some CSS rules.

Теперь нам необходимо добавить некоторые CSS-правила

History of edits (Latest: StaSa 2 years, 5 months ago) §

div.sc_menu {

div.sc_menu {

History of edits (Latest: MaxPv 2 years, 6 months ago) §

/* Set it so we could calculate the offsetLeft */

/* Устанавливаем это, чтобы посчитать offsetLeft */

History of edits (Latest: stryaponoff 1 year, 10 months ago) §

position: relative;

position: relative;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

height: 145px;

height: 145px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

width: 500px;

width: 500px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

/* Add scroll-bars */

/* Добавляем полосы прокрутки */

History of edits (Latest: stryaponoff 1 year, 10 months ago) §

overflow: auto;

overflow: auto;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

}

}

History of edits (Latest: MaxPv 2 years, 6 months ago) §

ul.sc_menu {

ul.sc_menu {

History of edits (Latest: MaxPv 2 years, 6 months ago) §

display: block;

display: block;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

height: 110px;

height: 110px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

/* Max width here, for users without Javascript */

/* Здесь максимальная ширина, для пользователей с отключенным JavaScript */

History of edits (Latest: stryaponoff 1 year, 10 months ago) §

width: 1500px;

width: 1500px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

padding: 15px 0 0 15px;

padding: 15px 0 0 15px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

/* Remove default margin */

/* Убрать поля, заданные по умолчанию */

History of edits (Latest: StaSa 2 years, 5 months ago) §

margin: 0;

margin: 0;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

background: url('navigation.png');

background: url('navigation.png');

History of edits (Latest: MaxPv 2 years, 6 months ago) §

list-style: none;

list-style: none;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

}

}

History of edits (Latest: MaxPv 2 years, 6 months ago) §

.sc_menu li {

.sc_menu li {

History of edits (Latest: MaxPv 2 years, 6 months ago) §

display: block;

display: block;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

float: left;

float: left;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

padding: 0 4px;

padding: 0 4px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

}

}

History of edits (Latest: MaxPv 2 years, 6 months ago) §

.sc_menu a {

.sc_menu a {

History of edits (Latest: MaxPv 2 years, 6 months ago) §

display: block;

display: block;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

text-decoration: none;

text-decoration: none;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

}

}

History of edits (Latest: MaxPv 2 years, 6 months ago) §

.sc_menu span {

.sc_menu span {

History of edits (Latest: MaxPv 2 years, 6 months ago) §

/* We want a caption to display on the next line */

/* Мы хотим отобразить заголовок в следующей строке*/

History of edits (Latest: space_indus 1 year, 9 months ago) §

— не уверен что я вычиткой занимаюсь)) space_indus

display: block;

display: block;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

margin-top: 3px;

margin-top: 3px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

text-align: center;

text-align: center;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

font-size: 12px;

font-size: 12px;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

color: #fff;

color: #fff;

History of edits (Latest: MaxPv 2 years, 6 months ago) §

}

}

History of edits (Latest: MaxPv 2 years, 6 months ago) §

The “width” and “overflow” properties are used to add a scroll-bar to the wrapper div. We set the “position” property for easier offset calculation with Javascipt. Don’t forget that offset is always calculated relative to the positioned parent. You can view what we’ve done so far here

Свойства «width» и «overflow» используются для добавления полосы прокрутки в div-контейнере. Мы установили свойство «position» для упрощения расчёта отступов с Javascipt. Не забывайте, что расчет отступов всегда вычисляется относительно позиционированного родительского элемента. Вы можете посмотреть, что у нас получилось

History of edits (Latest: mk93 1 year, 9 months ago) §
Pages: ← previous Ctrl next
1 2 3