jQuery中是否有实现以下功能的blink插件?
指定一个$target,然后它将向$target闪烁 它用于在提交表单时通知用户正确填写哪一部分 编辑:jQuery中是否有实现以下功能的blink插件?,jquery,plugins,Jquery,Plugins,指定一个$target,然后它将向$target闪烁 它用于在提交表单时通知用户正确填写哪一部分 编辑: 特别是,我想闪烁的是一个。您可以创建这样的函数。由于您没有指定它应该如何闪烁或闪烁多少次,我让它将背景颜色更改为红色,然后在500毫秒后将其更改回以前的颜色。这会让它看起来像是在眨眼 function blink($target) { // Set the color the field should blink in var backgroundColor = 'red
特别是,我想闪烁的是一个。您可以创建这样的函数。由于您没有指定它应该如何闪烁或闪烁多少次,我让它将背景颜色更改为红色,然后在500毫秒后将其更改回以前的颜色。这会让它看起来像是在眨眼
function blink($target) {
// Set the color the field should blink in
var backgroundColor = 'red';
var existingBgColor;
// Load the current background color
existingBgColor = $target.css('background-color');
// Set the new background color
$target.css('background-color', backgroundColor);
// Set it back to old color after 500 ms
setTimeout(function() { $target.css('background-color', existingBgColor); }, 500);
}
当您想调用闪烁功能时,只需执行以下操作:
function processForm() {
blink($("#name"));
}
如果您有一个ID为'name'
闪烁选择元素 HTML:
实际上我也做了类似的事情。我想让一个div闪烁,直到满足一个条件(该div已被单击并触发onclick事件) 此函数本质上是添加和删除CSS类,直到被if中断。将其应用于具有以下内容的图元:
blink($("#ItemToBlink"));
我有点喜欢这个:
function blink($target, $backgroundColor, $interval, $times) {
// Load the current background color
var existingBgColor = $target.css('background-color');
for (var i = 0; i != $times; ++i) {
// Set the new background color
setTimeout(function () { $target.css('background-color', $backgroundColor); }, $interval * i * 2);
// Set it back to old color
setTimeout(function () { $target.css('background-color', existingBgColor); }, $interval * (i * 2 + 1));
}
}
如果您的页面很长,您可能还需要添加边框和滚动条,如何使其应用于元素?我尝试了您的代码,但不起作用。
function blink($target) {
if (X == Y) {
$target.removeClass("BlinkClass");
} else {
$target.addClass("BlinkClass");
setTimeout(function() { $target.removeClass("BlinkClass"); }, 500);
setTimeout(function() { blink($target); }, 700);
}
}
blink($("#ItemToBlink"));
function blink($target, $backgroundColor, $interval, $times) {
// Load the current background color
var existingBgColor = $target.css('background-color');
for (var i = 0; i != $times; ++i) {
// Set the new background color
setTimeout(function () { $target.css('background-color', $backgroundColor); }, $interval * i * 2);
// Set it back to old color
setTimeout(function () { $target.css('background-color', existingBgColor); }, $interval * (i * 2 + 1));
}
}