0
此代码在将自定义阴影调整为图像高度方面效果很好。但是,如果我将其应用于页面上不同大小的图像,则会将它们全部调整为第一个图像大小。我如何使它更具体?消隐语法。如何将css更改应用于jquery中的此对象
<li class="col third impact-home">
<div class="image-with-overlay">
<%= image_tag 'impact.jpg', :class => "image-with-shadow" %>
<div class="image-shadow"></div>
</div>
</li>
$(document).ready(function() { //Fires when DOM is loaded
getImageSizes();
$(window).resize(function() { //Fires when window is resized
getImageSizes();
});
});
function getImageSizes() {
var imgHeight = $(".image-with-shadow").height();
var imgMargin = (- imgHeight) * .995;
console.log(imgMargin);
$(".image-shadow").css({"height": imgHeight});
$(".image-shadow").css({"margin-top": imgMargin});
}
希望你知道你取得第1的对象的参数的大小从对象的数组中的'$( “图像配-与阴影”)'。为了简单起见,将它添加到一个循环中,这将按需要工作 – Sagar
您也可以制作一个jQuery插件,然后将其用于任何特定图像。对于插件文档检查这个(https://learn.jquery.com/plugins/basic-plugin-creation) – Aman
这是没有HTML没有意义 – zer00ne