简体   繁体   English

data-image-src(Parallax.js)无法正常工作

[英]data-image-src(Parallax.js) not working correctly

I use Parallax.js but that not working correctly. 我使用Parallax.js,但不能正常工作。 I have used this library several times but this time <div /> expands style="background-image: ......" automatically X( Probably, other script prevented it. 我已经多次使用过这个库但是这次<div />会自动扩展style="background-image: ......" X(可能是其他脚本阻止了它。

 <div class="parallax" data-parallax="scroll" data-image-src="./assets/img/top.jpeg" data-speed="0.6" data-position="center top">
 </div>

currently: 目前:

 <div class="parallax" data-parallax="scroll" data-image-src="./assets/img/top.jpeg" data-speed="0.6" data-position="center top" style="background: url("./assets/img/top.jpeg") center top / cover;">
 </div>

should be: 应该:

 <div class="parallax" data-parallax="scroll" data-image-src="./assets/img/top.jpeg" data-speed="0.6" data-position="center top">
 </div>

You can delete the style property once the DOM is loaded. 加载DOM后,您可以删除style属性。

 document.addEventListener('DOMContentLoaded', () => { const div = document.querySelector('.parallax'); div.removeAttribute('style'); }); 
 <div class="parallax" data-parallax="scroll" data-image-src="./assets/img/top.jpeg" data-speed="0.6" data-position="center top"> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM