gpt4 book ai didi

javascript - css/javascript : checking pixels of image where hover effect is triggered

转载 作者:行者123 更新时间:2023-12-02 22:03:47 24 4
gpt4 key购买 nike

我遇到了一个关于简单悬停效果的棘手问题。我有某些图像(圆形,类型 .png,透明背景) - 当用户将鼠标悬停在任何图像上时,其颜色应该会改变(在这种情况下,我隐藏当前图像并显示其不同颜色的副本,使用 jquery .on(hover))。

但是,悬停效果表现得很有趣:有时会滞后(起飞前需要几秒钟/或者当从某个 Angular 落接近图像时,悬停效果会起作用,但从另一个 Angular 接近时则不会。我不知道没有应用任何转换延迟。

您可以在这里看到它:/url已删除/

您会注意到,一张图像(内部有一盏灯的最小图像)速度特别慢/有问题。

所以我想知道是否有一种方法可以检查触发悬停的网页的“像素”,看看它是否是由图像类型/位置/等引起的...我怀疑的另一件事是缩放会影响悬停(我通过 CSS 将整个容器缩小到 0.8)。

非常感谢任何帮助。

如果需要,这里是 html:

<div class="container-wrapper">
<div class="our-values-container">
<img src="/wp-content/uploads/2020/01/black-circle1.png" class="vimg1 hideblack">
<img src="/wp-content/uploads/2020/01/grey-circle2.png" class="vimg2 grey">
<img src="/wp-content/uploads/2020/01/grey-circle3.png" class="vimg3 grey">
<img src="/wp-content/uploads/2020/01/grey-circle4.png" class="vimg4 grey">
<img src="/wp-content/uploads/2020/01/grey-circle5.png" class="vimg5 grey">
<img src="/wp-content/uploads/2020/01/grey-circle6.png" class="vimg6 grey">
<!------------------------------------------->
<img src="/wp-content/uploads/2020/01/grey-circle1.png" class="vimg1 grey">
<img src="/wp-content/uploads/2020/01/black-circle2.png" class="vimg2 hideblack">
<img src="/wp-content/uploads/2020/01/black-circle3.png" class="vimg3 hideblack">
<img src="/wp-content/uploads/2020/01/black-circle4.png" class="vimg4 hideblack">
<img src="/wp-content/uploads/2020/01/black-circle5.png" class="vimg5 hideblack">
<img src="/wp-content/uploads/2020/01/black-circle6.png" class="vimg6 hideblack">
<!-------------------------------------------->
<img src="/wp-content/uploads/2020/01/text-box1.png" class="txt1 txtgrey">
<img src="/wp-content/uploads/2020/01/text-box2-grey.png" class="txt2 txtgrey">
<img src="/wp-content/uploads/2020/01/text-box3-real-grey.png" class="txt3 txtgrey">
<img src="/wp-content/uploads/2020/01/text-box3-grey.png" class="txt4 txtgrey">
<img src="/wp-content/uploads/2020/01/text-box5-grey.png" class="txt5 txtgrey">
<img src="/wp-content/uploads/2020/01/text-box6-grey.png" class="txt6 txtgrey">

</div>
</div>

这是CSS的主要部分:

  .our-values-container img{
position: absolute;
}
img.vimg1{
top: 150px;
left: -12px;
height: 123px;
}
img.vimg2{
top: 225px;
left: 97px;
height: 130px;
}

//the rest of the images are position in a similar manner
img.txtgrey{
height: 280px;
}

img.hideblack{
display: none;
}
img.grey.vimg1{
display: none;
}
img.hideblack.vimg1{
display: block;
}
.container-wrapper{
transform: scale(0.8, 0.8); //the initial size was slightly bigger than needed
//and I realized this after I positioned everything, so I resolved to
//scale it down.
}

JavaScript 函数:

function ourValues_page() {
if ($(window).width() > 960) {
$(".vimg1.grey").hover(function () {
makeAllGrey2();
$(".vimg1.grey").hide();
$(".vimg1.hideblack").show();
$(".txt1").attr("src", "/wp-content/uploads/2020/01/text-box1.png");

}, function () {});
$(".vimg2.grey").hover(function () {
makeAllGrey2();
$(".vimg2.grey").hide();
$(".vimg2.hideblack").show();
$(".txt2").attr("src", "/wp-content/uploads/2020/01/text-box2.png");

}, function () {

});
$(".vimg3.grey").hover(function () {
makeAllGrey2();
$(".vimg3.grey").hide();
$(".vimg3.hideblack").show();
$(".txt3").attr("src", "/wp-content/uploads/2020/01/text-box3-real.png");


}, function () {});
$(".vimg4.grey").hover(function () {
makeAllGrey2();
$(".vimg4.grey").hide();
$(".vimg4.hideblack").show();
$(".txt4").attr("src", "/wp-content/uploads/2020/01/text-box3.png");

}, function () {});
$(".vimg5.grey").hover(function () {
makeAllGrey2();
$(".vimg5.grey").hide();
$(".vimg5.hideblack").show();
$(".txt5").attr("src", "/wp-content/uploads/2020/01/text-box5.png");
}, function () {});
$(".vimg6.grey").hover(function () {
makeAllGrey2();
$(".vimg6.grey").hide();
$(".vimg6.hideblack").show();
$(".txt6").attr("src", "/wp-content/uploads/2020/01/text-box6.png");

}, function () {

});


}

function makeAllGrey2() {
$(".our-values-page .hideblack").hide();
$(".our-values-page .grey").show();

$(".txt1.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box1-grey.png");
$(".txt2.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box2-grey.png");
$(".txt3.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box3-real-grey.png");
$(".txt4.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box3-grey.png");
$(".txt5.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box5-grey.png");
$(".txt6.txtgrey").attr("src", "/wp-content/uploads/2020/01/text-box6-grey.png");
}
}

最佳答案

我不确定这是最好的方法,但您的问题是某些图像相互重叠,因此图标上的悬停无法正常工作。

enter image description here

此图像显示,当我右键单击并检查灯图标时,我实际上将鼠标悬停在协作内容图像上。

如果您在图标上放置 z-index: 2; ,它们会与内容图像重叠,因此您至少应该能够使悬停正常工作。

关于javascript - css/javascript : checking pixels of image where hover effect is triggered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59787905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com