[英]Either toggling or remove class A and add class B on click with a delay
I have a jQuery mobile page that has a jQuery chat feature. 我有一个具有jQuery聊天功能的jQuery移动页面。 Essentially I type something into the chat and then a few seconds later the bot responds.
从本质上讲,我在聊天中输入了一些内容,然后在几秒钟后,机器人进行了响应。
Behind the chat feature and filling up the whole page is a class that has a background image, and I wish to have it so when I type into the text field and hit SEND the background image class toggles to another class which has a different background image. 聊天功能和整个页面的后面是一个具有背景图像的类,我希望拥有它,因此当我在文本字段中键入内容并单击“发送”时,背景图像类会切换到另一个具有不同背景图像的类。 I also wish it to have like a 2-3 second delay.
我也希望它有2-3秒的延迟。
I have tried 我努力了
$(function () {
$("#chatSend").click(function () {
$(this).parent(".tasteTheRainbow").toggleClass("orNot");
});
});
Here is my JSfiddle...the background image does not show up but its there. 这是我的JSfiddle ...背景图像没有显示,但是在那里。 https://jsfiddle.net/mattmega4/d9yodhtm/
https://jsfiddle.net/mattmega4/d9yodhtm/
One solution could be this: 一种解决方案可能是这样的:
$(this).closest(".tasteTheRainbow").fadeTo('fast', 0, function () {
$(this).toggleClass("orNot").fadeTo('fast', 1);
});
See the DEMO: https://jsfiddle.net/d9yodhtm/3/ 参见演示: https : //jsfiddle.net/d9yodhtm/3/
I found a partial answer to my question. 我找到了部分答案。 I can get the image to change, but not the delay, but I can keep looking into that.
我可以改变图像,但不能改变延迟,但是我可以继续研究。 Here is the code:
这是代码:
$(document).ready(function(){
$("button#chatSend").click(function(){
$(".tasteTheRainbow").addClass("orNot");
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.