javascript - 尝试在 Firefox 中使用 jQuery 的转换时出现错误
问题描述
我正在尝试创建一个背景每 5 秒更改一次的 div,并带有“淡入淡出效果” 我在 Chrome 或 Opera 上做得很好,但在 Firefox 上不起作用,我不明白为什么!
在 Chrome 或 Opera 上,有一个非常漂亮的动画,但在 firefox 上,它只是跳过它,这不是我想要的
我希望有人能告诉我我所做的有什么问题
这是我所做的:
JAVASCRIPT:
$(document).ready(function() {
i=0;
setTimeout('changeBackground(' + i.toString() + ')', 5000);
});
function changeBackground(t){
switch (t) {
case 0:
i++;
$("#divBackground").css({
"background":"url(\"https://www.pets4homes.co.uk/images/articles/4295/large/early-neutering-of-kittens-pros-and-cons-598ddb68021a9.jpg\") no-repeat",
"background-size":"cover"
})
break;
case 1:
i++;
$("#divBackground").css({
"background":"url(\"https://images.ecosia.org/uRXcSxMTTPCdVhkGK51EG4phWdU=/0x390/smart/http%3A%2F%2Fmedias.demooniak.com%2Fphoto%2Fchat-drole%2Ftb%2Fphoto-chat-drole-131.jpg\") no-repeat",
"background-size":"cover"
})
break;
case 2:
i++;
$("#divBackground").css({
"background":"url(\"https://www.wikichat.fr/wp-content/uploads/sites/2/comment-soigner-une-plaie-dun-chat.jpg\") no-repeat",
"background-size":"cover"
})
break;
case 3:
i=0;
$("#divBackground").css({
"background":"url(\"http://cbsnews2.cbsistatic.com/hub/i/r/2015/04/15/4eb2c283-6625-4250-80e8-c580cb7a3ff1/thumbnail/1200x630/35cbdb30d7722e0e95e67c1738815e47/istock000033109430double.jpg\") no-repeat",
"background-size":"cover"
})
break;
}
setTimeout('changeBackground(' + i.toString() + ')', 5000);
}
#about .container#divBackground{
height:200px;
background: url("http://cbsnews2.cbsistatic.com/hub/i/r/2015/04/15/4eb2c283-6625-4250-80e8-c580cb7a3ff1/thumbnail/1200x630/35cbdb30d7722e0e95e67c1738815e47/istock000033109430double.jpg") no-repeat;
background-size: cover;
padding-top: 15px;
border-radius: 20px;
border: 3px solid #303a3b;
-moz-transition : all 0.8s ease-in 0s;
-webkit-transition: all 0.8s ease-in 0s;
-moz-transition: all 0.8s ease-in 0s;
-o-transition: all 0.8s ease-in 0s;
transition: all 0.8s ease-in 0s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<section id="about" class="container-fluid">
<div class="container shadow-lg" id="divBackground">
</div>
</body>
解决方案
推荐阅读
- xml - Android Studio 布局编辑器上的设备预览不显示移动设备
- react-native - 遇到两个具有相同键的孩子 - 索引不起作用
- elasticsearch - 无法在 Elasticsearch 7.x 中使用映射更新索引
- regex - 我想在 perl 中进行搜索替换。我的文件有“time1”、“+time1”、“+time11”、“time11”之类的字符串。如何区分这4个字符串
- reactjs - React js - 自定义计时器回到 0:60 并在到达 00:00 后再次从那里开始倒计时
- python - 限制 LARK 中递归语法的深度
- perl - Perl:嵌套数据结构中的交叉引用?
- android - 无法使我的 TextView 可选择,我已在我的 xml 和 java 文件中设置 textIsSelectable true
- optimization - 有没有办法为不同长度的位串分配不同的适应度值?
- python - 在 Python Selenium 中为 Firefox 设置配置文件和二进制文件不会打开浏览器