drupal-8 - 无法让 enquire.js 与 drupal 8 一起使用
问题描述
我会在 Drupal 8 主题中使用这个 JS 库。所以我在我的项目中添加了它,然后在我的主题中添加了它:libraries.yml
at.enquire:
remote: https://raw.githubusercontent.com/WickyNilliams/enquire.js
version: "2.1.6"
license:
name: MIT
url: https://raw.githubusercontent.com/WickyNilliams/enquire.js/master/LICENSE
gpl-compatible: true
js:
https://cdnjs.cloudflare.com/ajax/libs/enquire.js/2.1.6/enquire.min.js: { type: external, minified: true }
dependencies:
- core/jquery
- core/matchmedia
然后加载 vi amy info.yml:
<script src="https://cdnjs.cloudflare.com/ajax/libs/enquire.js/2.1.6/enquire.min.js"></script>
在我的 js 文件中:
$(document).ready(function () {
enquire.register("screen and (min-width:768px) and (max-width:1024px) and (orientation: landscape) and (min-resolution:1dppx)", {
deferSetup : true,
setup : function() {
$(".acces_rubriques iframe").height('55vh').width('45vw');//Video Gde Taille HP
},
match : function() {
console.log('Enquire.js : BP pour: tabletlandscape');
//Video sur HP
$(".acces_rubriques iframe").height('55vh').width('65vw');//Video Gde Taille HP
},
unmatch : function() {
example.unmatch();
}
});//enquire.register(tabletlandscape)
});//Fin document.ready
但是我的 android Tab 上什么也没发生。
可能缺少什么?谢谢
解决方案
我想在 Drupal8 上采用 jquery v3 捆绑包。但我需要使用它来工作:
jQuery( document ).ready(function() {
//Enquire stuff here
}
并通过以下方式将 npm enquire.js 加载到 twig 模板中:
{{ attach_library('THEMENAME/npm.enquire') }}
并通过 THEMENAME.libraries.yml 正确的 JS:
npm.enquire:
version: VERSION
js:
#Chargement des JS ajoutées via NPM ou externes
node_modules/enquire.js/dist/enquire.min.js: {}
所以它现在可以工作了。:)
推荐阅读
- add - Pytorch - 逐元素添加二维张量行
- ruby - 使用 ruby-vips 将远程图像合并为一张图像
- javascript - 如何读取事件数据属性
- umbraco - Umbraco 8 - 复选框 (TrueFalse) 总是返回 False
- c++ - 设置类实例的变量
- wso2 - 一些 WSO2 默认属性的问题
- python - TKinter GUI 冻结直到子进程结束并实时输出到文本小部件
- javascript - 在构造函数中声明变量有什么用
- c# - 为什么生成 EDMX 时窗口会关闭?
- node.js - 在 Heroku 上托管时,Express 会话不保存护照用户 ID