- html - 我的下拉菜单的内容关闭得太快
- c# - 使用 Html Agility Pack 从网页中的表中获取值而不使用 "SelectNode'
- html - 内容容器下的 CSS 下拉菜单
- html - 如何停止嵌套列表重叠父列表?
我有三个背景图像,我想以 5 秒的间隔淡入和淡出。我还利用 native 引导轮播组件以 5 秒的间隔将文本滑入和滑出,以与不断变化和淡出的背景图像相匹配。
场景
问题 1:第一个背景图像将是页面加载时的默认背景图像。 5 秒后,第二个背景图像消失,同时轮播滑到第二个文本。又过了 5 秒,第三个背景图像淡入,轮播滑到下一个文本。
问题 2:bootstrap 轮播组件有一个指示器,单击该指示器后,它会切换并滑动到该轮播部分中的文本。我希望在单击轮播指示器时更改背景图像。也就是说,如果轮播指示器 1 被点击,背景图像应该淡化到第一个背景图像。这应该适用于第二个和第三个轮播指示器及其各自的背景图像。如果当前是事件轮播元素和背景图片,则背景图片不应更改和淡入被点击的图片。
现状
我已经能够使用 jquery 和我也在 stackoverflow 中获得的解决方案实现具有淡入淡出效果的背景图像。我还使用带有选项 (data-interval="5000") 的引导轮播组件完成了文本轮播,它将切换时间设置为 5 秒以匹配背景图像淡入和淡出的相同时间间隔,但仍然有明显的小延迟。如何消除明显的延迟?
图像有时会在褪色前闪烁。有没有更好更合适的方式来实现淡入淡出的效果,又不让图片闪烁?
即使我在单击时运行该功能,单击轮播指示器也不会切换背景图像并将背景图像淡入下一个图像。如何以正确的方式实现它?
这是我尝试过的:
var bgImageArray = ["1_ozdgvm.jpg", "2_vjtjfy.jpg", "3_oxpdx2.jpg"],
base = "https://res.cloudinary.com/iolamide/image/upload/v1604569872/home_banner_",
secs = 5;
bgImageArray.forEach(function(img) {
new Image().src = base + img;
// caches images, avoiding white flash between background replacements
});
function backgroundSequence() {
window.clearTimeout();
var k = 0;
for (i = 0; i < bgImageArray.length; i++) {
setTimeout(function() {
document.getElementById('animated-bg').style.backgroundImage = "url(" + base + bgImageArray[k] + ")";
// document.getElementById('animated-bg').style.backgroundSize ="cover";
if ((k + 1) === bgImageArray.length) {
setTimeout(function() {
backgroundSequence()
}, (secs * 1000))
} else {
k++;
}
}, (secs * 1000) * i)
}
}
backgroundSequence();
$('.carousel-item').click(function() {
backgroundSequence();
})
*,
*::before,
*::after {
margin: 0;
padding: 0;
}
html {
box-sizing: border-box;
}
body {
box-sizing: inherit;
color: #fff !important;
}
.animated-bg {
background-image: url("https://res.cloudinary.com/iolamide/image/upload/v1604569872/home_banner_1_ozdgvm.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
transition: background 1s;
height: 694px;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.animated-bg:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.container {
padding: 3rem;
border-radius: 20px;
width: 700px;
background: rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
.text-top p {
width: 400px;
margin: 30px auto;
text-align: center;
}
h1 {
margin-top: 0;
text-align: center;
font-weight: 600;
}
.carousel-item p {
width: 330px;
text-align: center;
}
.carousel-indicators {
bottom: -50px !important;
}
@media only screen and (max-width: 800px) {
.container {
padding: 2rem;
width: 90%;
}
}
@media only screen and (max-width: 500px) {
.text-top p {
width: 80%;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="animated-bg" id="animated-bg">
<div class="container">
<div class="text-top" id="texttop">
<h1>Crossfade and Text Carousel</h1>
<p>Fade background image and swipe text at the same time. Also fade the background image to the one that matches the carousel's text when the carousel's indicator is clicked</p>
</div>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="5000">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<p>
Carousel Text One
</p>
</div>
<div class="carousel-item">
<p>Carousel Text Two</p>
</div>
<div class="carousel-item">
<p>Carousel Text Three</p>
</div>
</div>
</div>
</div>
</div>
最佳答案
您不需要自己对图像施以魔法的所有逻辑。您可以使用 carousel api on('slide.bs.carousel')
收听幻灯片变化并相应地切换图像。
const bgImageArray = ["1_ozdgvm.jpg", "2_vjtjfy.jpg", "3_oxpdx2.jpg"],
base = "https://res.cloudinary.com/iolamide/image/upload/v1604569872/home_banner_";
bgImageArray.forEach(function(img) {
new Image().src = base + img;
// caches images, avoiding white flash between background replacements
});
$('.carousel'). on('slide.bs.carousel', function(e) {
$('.animated-bg').css({
backgroundImage: `url(${base}${bgImageArray[e.to]})`
});
});
*,
*::before,
*::after {
margin: 0;
padding: 0;
}
html {
box-sizing: border-box;
}
body {
box-sizing: inherit;
color: #fff !important;
}
.animated-bg {
background-image: url("https://res.cloudinary.com/iolamide/image/upload/v1604569872/home_banner_1_ozdgvm.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
transition: background 1s;
height: 694px;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.animated-bg:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.container {
padding: 3rem;
border-radius: 20px;
width: 700px;
background: rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
.text-top p {
width: 400px;
margin: 30px auto;
text-align: center;
}
h1 {
margin-top: 0;
text-align: center;
font-weight: 600;
}
.carousel-item p {
width: 330px;
text-align: center;
}
.carousel-indicators {
bottom: -50px !important;
}
@media only screen and (max-width: 800px) {
.container {
padding: 2rem;
width: 90%;
}
}
@media only screen and (max-width: 500px) {
.text-top p {
width: 80%;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="animated-bg" id="animated-bg">
<div class="container">
<div class="text-top" id="texttop">
<h1>Crossfade and Text Carousel</h1>
<p>Fade background image and swipe text at the same time. Also fade the background image to the one that matches the carousel's text when the carousel's indicator is clicked</p>
</div>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="5000">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<p>
Carousel Text One
</p>
</div>
<div class="carousel-item">
<p>Carousel Text Two</p>
</div>
<div class="carousel-item">
<p>Carousel Text Three</p>
</div>
</div>
</div>
</div>
</div>
关于javascript - 使用 Bootstrap 文本轮播淡入和淡出背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64695070/
表架构 DROP TABLE bla; CREATE TABLE bla (id INTEGER, city INTEGER, year_ INTEGER, month_ INTEGER, val I
我需要拆分字符串/或从具有以下结构的字符串中获取更容易的子字符串。 字符串将来自 window.location.pathname 或 window.location.href,看起来像 text/n
每当将对象添加到数组中时,我都会尝试更新 TextView ,并在 TextView 中显示该文本,如下所示: "object 1" "object 2" 问题是,每次将新对象添加到数组时,它都会覆盖
我目前正在寻找使用 Java 读取网站可见文本并将其存储为纯文本字符串的方法。 换句话说,我想转换成这样: Hello stupid World进入“ Hello World ” 或者类似的东西 Un
我正在尝试以文本和 HTML 格式发送电子邮件,但无法正确发送正确的 header 。特别是,我想设置 Content-Type header ,但我找不到如何为 html 和文本部分单独设置它。 这
我尝试了上面的代码,但我无法绑定(bind)文本,我怎样才能将资源内部文本 bloc
我刚刚完成了 Space Shooter 教程,由于没有 GUIText 对象,所以我创建了 UI.Text 对象并进行了相应的编码。它在统一播放器中有效,但在构建 Web 应用程序后无效。我花了一段
我有这个代码: - (IBAction)setButtonPressed:(id)sender { NSUserDefaults *sharedDefaults = [[NSUserDefau
抱歉标题含糊不清,但我想不出我想在标题中做什么。无论如何,对于图像上的文本,我使用了 JLabel 文本并将其添加到图标中。 JLabel icon = new JLabel(new Imag
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我在将 Twitter 嵌入到我从 HTML 5 转换的 wordpress 运行网站时遇到问题。 我遇到的问题是推文不是我的自定义字体... 这是我无法使用任何 css 定位的 HTML 代码,我正
我正在尝试找到解决由于使用以下形式的代码而导致的冗余字符串连接问题的最佳方法: logger.debug("Entering loop, arg is: " + arg) // @1 在大多数情况下,
我写了这个测试 @Test public void removeRequestTextFromRouteError() throws Exception { String input = "F
我目前正在创建一个正则表达式来拆分所有匹配以下格式的字符串:&[文本],并且需要获取文本。字符串可能类似于:something &[text] &[text] everything &[text] 等
有没有办法将标题文本从一个词变形为另一个词,同时保留两个词中使用的字母?我看过的许多 css 文本动画大多是视觉的,很少有旋转整个单词的。 我想要做的是从一个词过渡,例如“BEACH”到“CHANGE
总结matplotlib绘图如何设置坐标轴刻度大小和刻度。 上代码: ?
我在容器 (1) 中创建了容器 (2)。你能帮忙如何向容器(1)添加文本吗?下面是我的代码 return Scaffold( body: Padding( padding: c
我似乎找不到任何人或任何人这样做过。我试图限制我们使用的图像数量,并想创建一个带有渐变作为其“颜色”的文本,并在其周围设置渐变轮廓/描边 到目前为止,我还没有看到任何将两者结合在一起的东西。 我可以自
我正在为视频游戏暗黑破坏神 2 使用 discord.py 构建一个不和谐机器人。其中一项功能要求机器人从暗黑破坏神 2 屏幕截图中提取项目的名称和属性。我目前正在为此使用 pytesseract,但
我很难弄清楚如何旋转 strip.text theme 中的属性来自 ggplot2 .我使用的是 R 版本 3.4.2 和 ggplot2 版本 2.2.1。 以下是 MWE 的数据。 > dput
我是一名优秀的程序员,十分优秀!