将JQuery Fade效果合并到删除和添加类中(Incorporate JQuery Fade effect into removing and adding classes)

编程入门 行业动态 更新时间:2024-10-26 10:29:19
将JQuery Fade效果合并到删除和添加类中(Incorporate JQuery Fade effect into removing and adding classes)

我有这个代码,可以更改应用于元素的类,这些类包含背景图像。 我想让图像淡入淡出而不仅仅是切换。

$(document).ready( function(){ var toggleImage = function(){ if($(".home").hasClass("home1")){ $(".home").removeClass("home1").addClass("home2"); console.log("First IF"); } else if($(".home").hasClass("home2")){ $(".home").removeClass("home2").addClass("home3"); console.log("Second IF"); } else if($(".home").hasClass("home3")){ $(".home").removeClass("home3").addClass("home1"); console.log("Third IF"); } console.log("End of the conditionals"); } console.log("Outside of the conditionals"); setInterval(toggleImage, 5000) });

i have this code that changes the classes that apply to an element and those classes contain a background image. i want to make the images fade in and out as opposed to just switching.

$(document).ready( function(){ var toggleImage = function(){ if($(".home").hasClass("home1")){ $(".home").removeClass("home1").addClass("home2"); console.log("First IF"); } else if($(".home").hasClass("home2")){ $(".home").removeClass("home2").addClass("home3"); console.log("Second IF"); } else if($(".home").hasClass("home3")){ $(".home").removeClass("home3").addClass("home1"); console.log("Third IF"); } console.log("End of the conditionals"); } console.log("Outside of the conditionals"); setInterval(toggleImage, 5000) });

最满意答案

你问的是不可能直接的。 您将需要使用CSS3淡入淡出效果( http://webdesign.about.com/od/css3tutorials/a/fade-in-and-out-with-css3.htm )

What you are asking is not possible directly. You will need to use CSS3 fade effect(http://webdesign.about.com/od/css3tutorials/a/fade-in-and-out-with-css3.htm)

更多推荐

toggleImage,console,log,home,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-08-07 16:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类中   并到   效果   Fade   JQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!