jquery上移下移插件_jQuery链接微移插件

jquery上移下移插件

A while back I debuted a tasteful mouseover/mouseout technique called link nudging. It started with a MooTools version and shortly thereafter a jQuery version. Just recently Drew Douglass premiered a jQuery plugin that aimed at producing the same type of effect. I've taken some time to put together my own version of the jQuery nudging plugin.

不久前,我推出了一种称为链接轻推的高雅鼠标悬停/鼠标悬停技术。 它以MooTools版本开始,此后不久是jQuery版本 。 就在最近,Drew Douglass首次发布了一个jQuery插件 ,旨在产生相同类型的效果。 我花了一些时间整理自己的jQuery nudging插件版本。

jQuery JavaScript (The jQuery JavaScript)


//Define the plugin
$.fn.nudge = function(params) {
	//set default parameters
	params = $.extend({
		amount: 20,				//amount of pixels to pad / marginize
		duration: 300,			//amount of milliseconds to take
		property: 'padding', 	//the property to animate (could also use margin)
		direction: 'left',		//direction to animate (could also use right)
		toCallback: function() {},	//function to execute when MO animation completes
		fromCallback: function() {}	//function to execute when MOut animation completes
	}, params);
	//For every element meant to nudge...
	this.each(function() {
		//variables
		var $t = $(this);
		var $p = params;
		var dir = $p.direction;
		var prop = $p.property + dir.substring(0,1).toUpperCase() + dir.substring(1,dir.length);
		var initialValue = $t.css(prop);
		/* fx */
		var go = {}; go[prop] = parseInt($p.amount) + parseInt(initialValue);
		var bk = {}; bk[prop] = initialValue;
		
		//Proceed to nudge on hover
		$t.hover(function() {
					$t.stop().animate(go, $p.duration, '', $p.toCallback);
				}, function() {
					$t.stop().animate(bk, $p.duration, '', $p.fromCallback);
				});
	});
	return this;
};

/* usages */
$(document).ready(function() {
	/* usage 1 */
	$('#nudgeUs li a').nudge();
	/* usage 2 */
	$('#nudgeUs2 li a').nudge({
		property: 'margin',
		direction: 'left',
		amount: 30,
		duration: 400,
		toCallback: function() { $(this).css('color','#f00'); },
		fromCallback: function() { $(this).css('color','#000'); }
	});
});


I've made Drew's script a bit more flexible by allowing the developer to set the property and direction to animate the element to and from. This plugin also detects the animated property's original settings so the developer doesn't need to set it. For kicks I also allow the developer to set the animate callback in case the developer wants to do some really creative stuff. My plugin is a bit larger in size but the extra file size enhances the plugin's worth.

通过允许开发人员设置属性和方向来使元素来回动画,我使Drew的脚本更加灵活。 该插件还检测动画属性的原始设置,因此开发人员无需进行设置。 对于踢球,我还允许开发人员设置动画回调,以防开发人员想要做一些真正有创意的事情。 我的插件尺寸较大,但是额外的文件大小增加了插件的价值。

Have more ideas for the plugin? Share them!

对插件有更多想法吗? 分享他们!

翻译自: https://davidwalsh.name/jquery-link-nudge

jquery上移下移插件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值