JS实现元素的抖动效果

JS文字抖动效果

大gai好! 这是使用JS实现元素的抖动效果 干货如下:

jQuery.fn.shake = function (intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
	    this.each(function () {
	        var jqNode = $(this);
	        jqNode.css({ position: 'relative' });
	        for (var x = 1; x <= intShakes; x++) {
	            jqNode.animate({ left: (intDistance * -1) }, (((intDuration / intShakes) / 4)))
	            .animate({ left: intDistance }, ((intDuration / intShakes) / 2))
	            .animate({ left: 0 }, (((intDuration / intShakes) / 4)));
	        }
	    });
	    return this;
	}

//调用
$(“类或ID选择器”).shake(2, 10, 400);

猜你喜欢

转载自blog.csdn.net/weixin_42272900/article/details/86689856