如何重置DOM中的Jquery效果

时间:2016-10-06 19:02:44

标签: javascript jquery

我希望能够点击画布,将其放在地图上,然后再次点击它以在地图中移动它。我试图用匿名函数做到这一点,但它不起作用。这是演示的链接和我到目前为止的代码

https://pokemon-map-electro2k.c9users.io/index.html

// Anonymous function
var movecanvas = function () {
    return onmousemove();
};

var onmousemove = function ($canvas) {

    // Make canvas follow cursor in the map area
    $(".map").mousemove(function (e) {

        $(".map ul li." + $canvas).offset({
            left: e.pageX,
            top: e.pageY
        });
    }).click(function () {
        // Disable mousemove when canvas is clicked within a map. Drop the canvas on the map
        $(".map").unbind("mousemove");

        // When canvas is click on again within the map area, make canvas follow cursor
        $(".map ul li").click(function () {
            movecanvas($canvas);  // Repeat $(".map").mousemove over here. But how??
        });
    });





    // De-select canvas if click on .palette div and reset Jquery effect
    $(".palette ul li." + $canvas).click(function () {
        $(".map ul li." + $canvas).fadeOut("slow", function () {$(".map ul li." + $canvas).remove()});
        $($container).find("." + $canvas).removeClass("selected");
        $("#document").replaceWith(paletteClone.clone(true));       // reset the DOM then manipulate it again
    });

    var paletteClone = $(document).clone(true);     // bound handler for .palette div

};

0 个答案:

没有答案