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

210 Views Asked by At

I am using jQuery-Lint (or more specifically FireQuery) to check my code which uses a drag operation. I've simplified it in the code below, but I still get the same messages from jQuery-Lint every time my mouse moves:

  • You've called css([object Arguments]) more than once on the same jQuery object
    • Why not combine these calls by passing an object? E.g. 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.

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?

<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>
1

There are 1 best solutions below

3
Dogbert On BEST ANSWER

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.