Home >Web Front-end >JS Tutorial >The left element implemented by jquery increases by N pixels. When the mouse is removed, it will slowly move to the original position_jquery

The left element implemented by jquery increases by N pixels. When the mouse is removed, it will slowly move to the original position_jquery

WBOY
WBOYOriginal
2016-05-16 18:31:47946browse

This control is developed based on Jquery. To reference the Jquery framework
control code

copy the code The code is as follows:

$.fn.myNudge = function() {
var self = $(this);
self.css({ position: "absolute" }); //Make this element absolutely positioned
var selfLeft = self.css("left");
var selfTop = self.css("top");
self.css({ left: selfLeft, top: selfTop }); //Set This element is the original position
self.hover(function() {
self.animate({ left: " =50px" }, 1000);
},
function() {
self.animate({ left: "-=50px" }, 1000);
}
);
}

Usage
HTML code
Copy code The code is as follows:

sadfsadfds

JAVASCRIPT code

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn