当点击某个元素时,我希望另一个元素的背景在返回其原始颜色之前变为红色x秒,所有这些都不使用UI jQuery,只有jQuery。有可能吗?
答案 0 :(得分:16)
var $el = $("#my-element"),
x = 5000,
originalColor = $el.css("background");
$el.css("background", "red");
setTimeout(function(){
$el.css("background", originalColor);
}, x);
答案 1 :(得分:3)
$("#element1_ID").on('click', function() { // click on first element
var bg = $("element2_ID").css('background'); // store original background
$("element2_ID").css('background', 'red'); //change second element background
setTimeout(function() {
$("element2_ID").css('background', bg); // change it back after ...
}, 1000); // waiting one second
});
答案 2 :(得分:0)
$('.b').on('click', function() {
var time = 2000;
setTimeout(function() {
$('.a').css("background-color", "green");
}, time);
});