简体   繁体   English

将固定div放在可拖动div(draggable.js)外部

[英]Put a fixed div outside a draggable div (draggable.js)

Im working around with the draggable.js and I am trying to let some text appear that is connected to the dragged DIV… 我正在处理draggable.js,我正在尝试显示一些与拖动的DIV连接的文本…

So, this works fine, but I want to let the specific text appear in the left-top corner of the browsers window, I tried to give it a position:fixed, but it always stays in the dragged DIV. 因此,这可以正常工作,但是我想让特定的文本出现在浏览器窗口的左上角,我试图给它指定一个位置:fixed,但是它始终停留在拖动的DIV中。

I tought it would be the .ui-draggable class that ist added to my .text DIV, but it was not! 我坚称这是ist添加到.text DIV中的.ui可拖动类,但事实并非如此!

<div class="drag axis" id="item_1"><div class="text">Some Text</div></div>
<div class="drag axis" id="item_2"><div class="text">Another Text</div></div>

CSS: CSS:

.text {
display: none;
position:fixed;
top: 40px;
left: 40px;}

#item_1 {
position: absolute;
top: 100px;
left: 50%;
width: 500px;
height: 100px;
background-color: blue;
z-index: 0;
cursor: pointer;}

#item_2 {
position: absolute;
top: 125px;
left: 30%;
width: 500px;
height: 200px;
background-color: red;
z-index: 0;
cursor: pointer;}

See my JS Fiddle to understand my problem better: https://jsfiddle.net/7bzvvpjL/4/ 请参阅我的JS小提琴以更好地理解我的问题: https : //jsfiddle.net/7bzvvpjL/4/

As i said, the text should always appear fixed, 40px, 40px, of the window and not inside the dragged div. 如我所说,文本应始终显示为窗口的固定像素(40px,40px),而不是在拖动的div内。

What am I doing wrong, does anybody have an idea? 我做错了什么,有人知道吗?

The problem is that the text position is inside the absolute positioned div. 问题是文本位置在绝对位置的div内。

I slightly modified your code to show how it could work (even there are several solutions). 我稍微修改了您的代码以显示其工作方式(即使有几种解决方案)。 What you need to do is moving your text-divs. 您需要做的是移动text-div。

HTML: HTML:

<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="drag axis" id="item_1"></div><label for="item_1" class="text">Some Text</label>
<div class="drag axis" id="item_2"></div><label for="item_2" class="text">Another Text</label>

CSS: CSS:

.text {
  position: fixed;
    display: none;
    top: 40px;
    left: 40px;
}

modofoed scripts: 变态脚本:

start: function( event, ui ) {
    $(this).addClass('color');
    //TODO: check if this.id == text.for or find by for property before fadingin
    $(".text").fadeIn("slow");//.css('position','fixed');
 },
 stop: function( event, ui ) {
     $(this).removeClass('color');
     //TODO (not necessary): check if this.id == text.for or find by for property
     $(".text").fadeOut("slow");
},

fiddle: https://jsfiddle.net/7bzvvpjL/7/ 小提琴: https : //jsfiddle.net/7bzvvpjL/7/

…i found a solution in putting the .text div outside the .drag div… …我找到了将.text div放在.drag div之外的解决方案…

and then writing in the JS 然后用JS编写

$(this).next(".text").fadeIn("slow");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM