gpt4 book ai didi

javascript - div 内的滚动 div 出现在具有较高 z-index 的 div 上

转载 作者:行者123 更新时间:2023-12-01 00:21:37 24 4
gpt4 key购买 nike

https://jsfiddle.net/09rcqwdf/1/

侧边栏具有更高的z-index容器 .main 具有 overflow: none, 其内部的 div 具有 overflow:scroll code> 但由于某种原因,当您拖动文本时,它认为它位于 .scrolling div 上,而实际上它位于 侧边栏 div.

<!doctype html>
<html class="no-js" lang="">

<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#fafafa">
<style>
body,
html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

#content {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
overflow: hidden;
}

.main {
position: absolute;
bottom: 0;
left: 300px;
right: 0;
top: 0;
overflow: hidden;
}

.scroll-container {
display: block;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
overflow: scroll;
z-index: 1;
}

.scrolling {
display: block;
overflow: hidden;
position: absolute;
left: 0;
top: 0;
z-index: 2;
width: 3500px;
height: 4000px
}

.sidebar {
display: block;
position: absolute;
background-color: #5555;
overflow: hidden;
z-index: 100000;
width: 300px;
bottom: 0;
top: 0;
left: 0;
}
</style>
</head>

<body>
<div id="content">
<div class="main">
<div class="scroll-container">
<div class="scrolling">

</div>
</div>
</div>
<div class="sidebar">
<div>
<div class="drag">Drag</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>
window.jQuery || document.write('<script src="js/vendor/jquery-3.4.1.min.js"><\/script>')
</script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
$('.scrolling').droppable({
tolerance: 'pointer',
accept: '.drag',
drop(event, ui) {
console.log(event);
console.log(ui);
if (ui.helper.hasClass('cancelled')) {
return;
}
},
});
$('.drag').draggable({
helper() {
const $helper = $('<div></div>');
$helper.text('drag');
return $helper.clone().addClass('dragged-component-helper');
},
start() {},
stop(event, ui) {
ui.helper[0].remove();
},
cursorAt: {
left: 0,
top: 5,
},
cancelOnEscape: true,
appendTo: '#content',
disabled: false,
distance: 0,
revert: 'invalid',
});
</script>
</body>

</html>

最佳答案

我注意到的第一件事是你的 helper 回调配置不正确,你有:

$('.drag').draggable({
helper() {
const $helper = $('<div></div>');
$helper.text('drag');
return $helper.clone().addClass('dragged-component-helper');
},
start() {
},

由于您要定义一个对象,因此您需要有键名、冒号,然后是函数。示例:

$('.drag').draggable({
helper: function() {
const $helper = $('<div></div>');
$helper.text('drag');
return $helper.clone().addClass('dragged-component-helper');
},
start: () => {
},

这可能会导致您的可拖动对象出现各种初始化问题,但令我惊讶的是它没有在您的控制台中显示为错误。

关于拖动 Action ,我认为这也会通过修正得到解决。

https://jsfiddle.net/Twisty/3gn57quj/10/

JavaScript

$(function() {
$('.scrolling').droppable({
tolerance: 'pointer',
accept: '.drag',
drop(event, ui) {
if (ui.helper.hasClass('cancelled')) {
return false;
}
$(this).append(ui.helper.clone().css({
left: (ui.offset.left - $(".sidebar").width()) + "px",
top: ui.offset.top + "px"
}));
},
});
$('.drag').draggable({
helper: function() {
return $("<div>", {
class: "drag component"
}).html("drag");
},
stop(event, ui) {
ui.helper[0].remove();
},
cursorAt: {
left: 0,
top: 5,
},
cancelOnEscape: true,
appendTo: '#content',
disabled: false,
distance: 0,
revert: 'invalid',
});
});

关于javascript - div 内的滚动 div 出现在具有较高 z-index 的 div 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60117909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com