简体   繁体   English

jQuery lint (FireQuery) 在拖动 div 时会发出大量警告

[英]jQuery lint (FireQuery) gives loads of warnings when dragging a div

I am using jQuery-Lint (or more specifically FireQuery) to check my code which uses a drag operation.我正在使用 jQuery-Lint(或更具体地说是 FireQuery)来检查我的使用拖动操作的代码。 I've simplified it in the code below, but I still get the same messages from jQuery-Lint every time my mouse moves:我在下面的代码中对其进行了简化,但每次鼠标移动时,我仍然会从 jQuery-Lint 收到相同的消息:

  • You've called css([object Arguments]) more than once on the same jQuery object您在同一个 jQuery object 上不止一次调用 css([object Arguments])
    • Why not combine these calls by passing an object?为什么不通过传递 object 来组合这些调用呢? Eg css({ "left": 63, "left": 64 })例如 css({ "left": 63, "left": 64 })

I know why I'm getting these messages, it's because I am changing the left property every time the mouse is moved, but this is the behavior I want because it is a drag operation.我知道为什么会收到这些消息,这是因为每次移动鼠标时我都会更改 left 属性,但这是我想要的行为,因为它是拖动操作。

Is there a better way for me to use jQuery to drag that won't cause these messages from jQuery lint, or do I just need to ignore them?有没有更好的方法让我使用 jQuery 拖动不会导致来自 jQuery lint 的这些消息,还是我只需要忽略它们?

<html>
    <head>
        <style>
            div {
                width     : 50;
                height    : 50;
                background: #f00;
                position  : absolute;
            }
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
        <script>
            $(function () {
                var $div = $("div");
                $div.css("cursor", "none");
                $(document).mousemove(function (event) {
                    $div.css("left", event.pageX - 25);
                });
            });
        </script>
    </head>
    <body>
        <div/>
    </body>
</html>

Those warnings don't make sense (for this use case), so you should ignore them.这些警告没有意义(对于这个用例),所以你应该忽略它们。

You do need to be able to set the left property on the $div on mousemove , to show the drag effect you want.您确实需要能够在mousemove上的 $div 上设置left属性,以显示您想要的拖动效果。

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

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