javascript - 根据滑块滑翔机js中的活动li值更改css值
问题描述
想要根据活动滑翔机 js li 值更改 css html 背景图像
这是CSS
html {
background-image: url("https://images.unsplash.com/photo-1496518908709-02b67989c265?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60");
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
我正在使用 Glider.js 所以当当前幻灯片在框架中时,一个类 glide__slide--active 被添加到
<div class="glide__track" data-glide-el="track">
<ul class="glide__slides">
<li class="glide__slide" data-image-value="https://bob.com/image/bigimage1.jpg">01</li>
<li class="glide__slide glide__slide--active" data-image-value="https://bob.com/image/bigimage2.jpg" >02</li>
<li class="glide__slide" data-image-value="https://bob.com/image/bigimage3.jpg">03</li>
</ul>
</div>
所以使用jquery更改背景图片的url,值为data-image-value
解决方案
根据glidejs 文档的事件部分,您可以收听过渡结束,如:
glide.on('move.after', function(event) {
// store the background in a variable
var newBG = $('.glide__slide--active').attr('data-image-value');
// apply the background image to the element (html or body...whatever you're using)
$('body').css('background-image', 'url(' + newBG + ')');
});
没有看到一个可重复的例子,这就是我能为你做的最好的事情。更多代码会有所帮助。
推荐阅读
- javascript - 未处理的“错误”事件^ ReferenceError:未定义下一个
- powershell - 如何在 Powershell 中运行它?
- regex - 正则表达式保持单词分组的首次出现
- angular - 当使用单元格渲染器框架格式化列时,选择/取消选择 ag 网格中复选框的所有选项
- r - 为什么在 R 中添加到我的数据框中的列是“列表”形式而不是数据类型的原因是什么?以及如何纠正?
- javascript - SyntaxError:使用 Let 的意外标识符
- pine-script - 我如何从分形点绘制线,这将延伸到价格穿过它的点
- python - sklearn 的 KFold 函数,带有 shuffle 和 random_state
- azure - 如何同时交换在 Azure 应用服务 Web 应用上运行的 2 层应用程序的部署槽?
- javascript - 调整 Safari 静音自动播放的视频音量