Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Draggable element on top

Автор: kudvenkat

Загружено: 2015-07-17

Просмотров: 17869

Описание:

Link for all dot net and sql server video tutorial playlists
https://www.youtube.com/user/kudvenka...

Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

In this video we will discuss
1. How to keep draggable element always on top of other draggable elements on the page
2. How to bring the element on top of other draggable elements on the page as soon as the mouse down event is triggered

Consider the following code

HTML

<div id="redDiv" class="divClass" style="background-color: red">
Red Div
</div>

<div id="greeDiv" class="divClass" style="background-color: green">
Green Div
</div>

<div id="blueDiv" class="divClass" style="background-color: blue">
Blue Div
</div>

<div id="brownDiv" class="divClass" style="background-color: brown">
Brown Div
</div>

CSS

<style>
.divClass {
font-family:Arial;
height: 150px;
width: 150px;
color: white;
display: table-cell;
vertical-align: middle;
text-align: center;
z-index:0
}
</style>

jQuery

$(document).ready(function () {
$('.divClass').draggable();
});

All the div elements on this page are draggable. The problem here is that, when you drag Red Div it does not stay on top of other draggable div elements on the page. Green Div on the other hand stays on top of Red Div but stays below Blue and Red Div elements. This is the default behaviour.
// Draggable element on top.png

To bring a Div Element that is being dragged on top of other draggable div's on the page, use stack option. The way this works is jQuery sets the z-index of the element that is being dragged to higher than the z-index of any other draggable div element on the page. You can see the value of the z-index in browser developer tools.
$(document).ready(function () {
$('.divClass').draggable({
stack: '.divClass'
});
});

However, if you simply click on a Div element without dragging then the element is not brought on to the top. Here is the code to bring the element on top as soon as mousedown event is triggered. All this function does is change the z-index of the div element to a value greater than the z-index of any other div element.

$(document).ready(function () {
$('.divClass').draggable();

$('.divClass').mousedown(function () {
var maxZindex = 0;
$(this).siblings('.divClass').each(function () {
var currentZindex = Number($(this).css('z-index'));
maxZindex = currentZindex > maxZindex ? currentZindex : maxZindex;
});
$(this).css('z-index', maxZindex + 1);
});
});

Draggable element on top

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

array(10) { [0]=> object(stdClass)#4626 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "-JFkAaLOou8" ["related_video_title"]=> string(23) "jquery droppable widget" ["posted_time"]=> string(19) "9 лет назад" ["channelName"]=> string(9) "kudvenkat" } [1]=> object(stdClass)#4599 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "hk-_CIF5Um8" ["related_video_title"]=> string(23) "jquery draggable widget" ["posted_time"]=> string(19) "9 лет назад" ["channelName"]=> string(9) "kudvenkat" } [2]=> object(stdClass)#4624 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "EbMR_nlIAkc" ["related_video_title"]=> string(18) "jquery menu widget" ["posted_time"]=> string(19) "9 лет назад" ["channelName"]=> string(9) "kudvenkat" } [3]=> object(stdClass)#4631 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "jfYWwQrtzzY" ["related_video_title"]=> string(61) "How To Build Sortable Drag & Drop With Vanilla Javascript" ["posted_time"]=> string(19) "5 лет назад" ["channelName"]=> string(18) "Web Dev Simplified" } [4]=> object(stdClass)#4610 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "I5OmqGPNu-U" ["related_video_title"]=> string(108) "США заявили о победе Украины / Президент резко изменил план" ["posted_time"]=> string(23) "5 часов назад" ["channelName"]=> string(10) "NEXTA Live" } [5]=> object(stdClass)#4628 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "jGO6QtWOPJQ" ["related_video_title"]=> string(174) "КАСЬЯНОВ: "Я видел это своими глазами. Это не публиковалось": что показали Путину, чего он боится" ["posted_time"]=> string(23) "5 часов назад" ["channelName"]=> string(24) "И Грянул Грэм" } [6]=> object(stdClass)#4623 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "BzFIMmt514s" ["related_video_title"]=> string(28) "jquery tooltip from database" ["posted_time"]=> string(19) "9 лет назад" ["channelName"]=> string(9) "kudvenkat" } [7]=> object(stdClass)#4633 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "5QKy-zNhyvs" ["related_video_title"]=> string(122) "Разница между войной в Европе и на Ближнем Востоке (English subtitles) @Max_Katz" ["posted_time"]=> string(21) "2 часа назад" ["channelName"]=> string(19) "Максим Кац" } [8]=> object(stdClass)#4609 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "pe_ejTiIcSs" ["related_video_title"]=> string(53) "Похудей на 45 КГ, Выиграй $250,000!" ["posted_time"]=> string(19) "4 дня назад" ["channelName"]=> string(7) "MrBeast" } [9]=> object(stdClass)#4627 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "_jVL2-x1vXQ" ["related_video_title"]=> string(128) "⚡️Трамп внезапно запросил помощь у Путина || Зеленского бросает НАТО?" ["posted_time"]=> string(24) "15 часов назад" ["channelName"]=> string(23) "Время Прядко" } }
jquery droppable widget

jquery droppable widget

jquery draggable widget

jquery draggable widget

jquery menu widget

jquery menu widget

How To Build Sortable Drag & Drop With Vanilla Javascript

How To Build Sortable Drag & Drop With Vanilla Javascript

США заявили о победе Украины / Президент резко изменил план

США заявили о победе Украины / Президент резко изменил план

КАСЬЯНОВ:

КАСЬЯНОВ: "Я видел это своими глазами. Это не публиковалось": что показали Путину, чего он боится

jquery tooltip from database

jquery tooltip from database

Разница между войной в Европе и на Ближнем Востоке (English subtitles) @Max_Katz

Разница между войной в Европе и на Ближнем Востоке (English subtitles) @Max_Katz

Похудей на 45 КГ, Выиграй $250,000!

Похудей на 45 КГ, Выиграй $250,000!

⚡️Трамп внезапно запросил помощь у Путина || Зеленского бросает НАТО?

⚡️Трамп внезапно запросил помощь у Путина || Зеленского бросает НАТО?

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]