this.offset({...})不是函数,但this.dataset.value读得不错?

时间:2017-01-14 09:48:19

标签: jquery this

我试图制作一个可拖动的div。我可以很好地操纵数据集,但我无法调整偏移量。我怀疑this关键字的某些内容让我感到沮丧,但我不确定是什么。为什么我可以读取this但不访问函数的属性?

$(".flyout")
    .mousedown(function() {
        this.dataset.moving = "true"; //works as intended
    })
    .mouseup(function() {
        this.dataset.moving = "false"; //works as intended
    })
    .mousemove(function(e) {
        var moving = this.dataset.moving; //works as intended
        if (moving == "true") {
            this.offset({ top: e.pageY, left: e.pageX }); //this.offset is not a function.
        }
    });

0 个答案:

没有答案