0

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>
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Grezzo
  • 2,220
  • 2
  • 22
  • 39

1 Answers1

1

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.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • Hi Dogbert. Thanks, that's what I thought. So is there a way of hiding the messages without lowering the logging level? At the moment, the list grows so fast, that the other (relevant) messages are buried in a sea of these irrelevant messages. – Grezzo Jul 05 '11 at 16:31
  • I think you can do that by removing `'css'` from this line https://github.com/jamespadolsey/jQuery-Lint/blob/master/jquery.lint.js#L765 – Dogbert Jul 05 '11 at 16:42
  • That seems a bit overkill, especially as I want to see other valid mentions of calling css() to frequently. I found that changing my code to $div.css({"left": event.pageX - 25}); stopped the warnings, and hopefully won't affect performance. – Grezzo Jul 06 '11 at 12:02