我遇到的情况是我无法使用Jquery UI.我试图在不使用Jquery UI的情况下获得Jquery UI Pulsate Effect.与此链接类似,http://docs.jquery.com/UI/Effects/Pulsate.我搜索了很多但找不到任何东西.
dfs*_*fsq 14
我不知道原始UI代码是什么样的,但这是使用animate函数的超级简单实现:
$.fn.pulse = function(options) {
var options = $.extend({
times: 3,
duration: 1000
}, options);
var period = function(callback) {
$(this).animate({opacity: 0}, options.duration, function() {
$(this).animate({opacity: 1}, options.duration, callback);
});
};
return this.each(function() {
var i = +options.times, self = this,
repeat = function() { --i && period.call(self, repeat) };
period.call(this, repeat);
});
};
$("div").click(function() {
$(this).pulse({times: 4, duration: 500});
});
Run Code Online (Sandbox Code Playgroud)
查看下面的演示或这个JsFiddle.
$("div").click(function() {
$(this).stop().pulse({times: 4, duration: 300});
});
$.fn.pulse = function(options) {
var options = $.extend({
times: 3,
duration: 1000
}, options);
var period = function(callback) {
$(this).animate({opacity: 0}, options.duration, function() {
$(this).animate({opacity: 1}, options.duration, callback);
});
};
return this.each(function() {
var i = +options.times, self = this,
repeat = function() { --i && period.call(self, repeat) };
period.call(this, repeat);
});
};Run Code Online (Sandbox Code Playgroud)
div {background-color: green; padding: 20px; display: inline-block;}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Click me</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6193 次 |
| 最近记录: |