jQuery 可拖动的奇怪行为

标签 jquery html css draggable

我正在使用 jQuery draggable 在屏幕上拖动单词“Hello”的单独字母,但我注意到了烦人的行为。

如果我将字母 H 向右拖动到字母 E、L、L 或 O 附近的任何位置,然后放下字母,我将无法再“拾起”字母,因为它现在“被困在下面” "其他字母的 h1(我将每个字母包装在一个单独的 h1 中)。这同样适用于被认为“低于”另一个字母的任何其他字母(H 是“最低”,O 是“最高”)。

这很难解释,所以我用 fiddle 来说明。将字母“H”拖到字母“E”的正上方(不是在上面),放手,然后尝试再次将其拾起,但您将无法(直到将“E”移出方式)。我在每个 h1 周围都加上了边框,这样您就可以看到是 h1 以某种方式阻止我拿起这封信。

奇怪的是,这只发生在 Chrome 中。我已经在 Win 7 的 IE10 中测试过了,没问题。

关于如何修复它有什么想法吗?

HTML:

<body>
  <div id="name">
      <h1 id="h" ><a href=#>H</a></h1>
      <h1 id="e" ><a href=#>E</a></h1>
      <h1 id="l" ><a href=#>L</a></h1>
      <h1 id="l2" ><a href=#>L</a></h1>
      <h1 id="o" ><a href=#>O</a></h1>
  </div>
</body>

CSS:

        body {
        font-family: 'Sigmar One', cursive;
        font-size: 75px;
        color: white;
        text-shadow: 5px 5px 5px #000;

        background-color:blue;

        width: 100%;
        height: 100%;
        margin: 0;
    }

    div {
        position:absolute; 
        height:100%; 
        width: 100%;
        display: table;
    }

    h1 {
        display: table-cell;
        vertical-align: middle;
        text-align:center;
        height: 1em;
        border: 1px solid black;
    }

    a {
        /*border: 1px solid black;*/
        display: inline-block;
        line-height: 100%;
        overflow: hidden;
    }

    a:visited, a:hover, a:active {
        text-decoration: none;
        color: white;
    }

    a:link {
        text-decoration: none;
        color: white;
        text-shadow: 3px -3px 0px black;
    }

    a:hover {
        text-shadow: 5px 5px 5px #000;
        color: white;
    }

jQuery:

    $(document).ready(function() {
        $("#h, #e, #l, #l2, #o").draggable({ handle: "a" });
    });

fiddle : http://jsfiddle.net/8Huu7/36/

最佳答案

使用 z-index 属性。 这是代码:

$(document).ready(function() {
        $("#h, #e, #l, #l2, #o").draggable({ 
            handle: "a",
            start: function(){
                $('#name h1').css('z-index', 99);
                $(this).css('z-index', 999);
            }
        });
    });

这是 fiddle : http://jsfiddle.net/8Huu7/41/

关于jQuery 可拖动的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18219893/

相关文章:

javascript - 如何防止 fadeIn/Out 在展开/折叠标题时闪烁?

node.js - 在网络浏览器中嵌入网络摄像机

html - 我一直在用两个 id 进行测试,第二个 id 没有做任何事情

jquery - 如何旋转菜单的人字形

html - 图像不工作

javascript - 为什么我的悬停功能无法正常工作?

javascript - `使用文本区域中的字符串动态填充下拉菜单

jquery - Lightgallery 之前的预加载器,使用 Imageloaded 的同位素

javascript - Android 平板电脑(Samsung galaxy 选项卡)- 表格在方向改变时弄乱了

javascript - JQuery 在不重新加载页面的情况下更新 div 的 HTML