I bought an HTML template only to find it uses jQuery 1. I am trying to upgrade to jQuery 3 but I have an issue with this piece of code in the template's main.js file:(我买了一个HTML模板,只是发现它使用jQuery1。我正在尝试升级到jQuery 3,但是模板的main.js文件中的这段代码存在问题:)
var background_image = function() {
$("[data-bg-img]").each(function() {
var attr = $(this).attr('data-bg-img');
if (typeof attr !== typeof undefined && attr !== false && attr !== "") {
$(this).css('background-image', 'url('+attr+')');
}
});
};
The HTML part this references is:(此引用的HTML部分是:)
<figure class="deal-thumbnail embed-responsive embed-responsive-16by9" data-bg-img="'.$dealimage.'">
This stopped working when upgrading to jQuery 3.4.1.(升级到jQuery 3.4.1时,此操作停止了。)
Not sure what to do.(不知道该怎么办。) I would appreciate any help I can get.(我将不胜感激。)
CSS:(CSS:)
*[data-bg-img] {
background-position: center;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
ask by Bruno translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…