简体   繁体   English

悬停淡入淡出不适用于石工CSS

[英]Hover fade not working with masonry CSS

I am working on my portfolio site, and on the works page, I have a pinterest-like masonry layout with images of some of my work. 我在自己的作品集网站上工作,在作品页面上,我有一个类似pinterest的砌体布局,其中包含一些作品的图像。 On hover of the images I am using css to show a caption box and this works as expected. 将鼠标悬停在图像上时,我正在使用CSS来显示标题框,并且按预期工作。 However, I want the image to fade without the caption box failing and when I add the hover fade on the image whether it be via CSS or javascript/jquery it only works properly on the first row of images. 但是,我希望图像在没有标题框失败的情况下褪色,并且当我在图像上添加悬停褪色时,无论是通过CSS还是javascript / jquery,它都只能在图像的第一行正常工作。 or rather it works properly on all rows but it breaks the caption box on any row aside from the first. 或者更确切地说,它可以在所有行上正常工作,但是它会破坏除第一行以外的任何标题栏。 It definitely seems to be something due to the rows I am using because if I change the css to only have one row it works as expected. 这肯定是由于我使用的行引起的,因为如果我将css更改为仅包含一行,则它可以按预期工作。

Here is the code of one of the image panels: 这是图像面板之一的代码:

<div class="panel panel-primary work-panel image text-center">
  <script id="metamorph-29-end" type="text/x-placeholder"></script>
    <div class="panel-image hide-panel-body hide-panel-footer">
  <div class="img-wrap">
      <img src="./imgs/abstract-realism.jpg" data-bindattr-1="1" class="panel-image-preview">
  <div class="img-overlay">
  <h4><script id="metamorph-30-start" type="text/x-placeholder"></script>Abstract Reality<script id="metamorph-30-end" type="text/x-placeholder"></script></h4>
      <p><script id="metamorph-31-start" type="text/x-placeholder"></script>This piece was completed during my studies at the Art Institute of Virginia Beach. The drawing was done in colored chalk and conte on paper.<script id="metamorph-31-end" type="text/x-placeholder"></script></p>
  </div>
  </div>
    </div>
    <div class="panel-body">
      <h4><script id="metamorph-32-start" type="text/x-placeholder"></script>Abstract Reality<script id="metamorph-32-end" type="text/x-placeholder"></script></h4>
      <p><script id="metamorph-33-start" type="text/x-placeholder"></script>This piece was completed during my studies at the Art Institute of Virginia Beach. The drawing was done in colored chalk and conte on paper.<script id="metamorph-33-end" type="text/x-placeholder"></script></p>
    </div>
  </div>

Here is the css controlling the caption box: 这是控制字幕框的CSS:

.img-wrap{
overflow:hidden;
position:relative;
}
.img-overlay {
background-color:#000;
bottom:0;
color:#fff;
opacity:0;
filter: alpha(opacity = 0);
position: absolute;
width:100%;
z-index:9999;
}
.img-overlay h4, .img-overlay p{
padding:0 10px;
}
.img-wrap:hover .img-overlay{
opacity:0.9;
filter: alpha(opacity = 90);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}

Here is the jquery on the ember view controlling the fade (the function starting with $('.img-wrap'): 这是在ember视图上控制淡入淡出的jquery(以$('。img-wrap'开头的函数):

    App.WorksfadeView = Ember.View.extend({
        didInsertElement : function(){
        Ember.run.scheduleOnce('afterRender', this, function(){
                $(function() {
                        $("a[rel^='prettyPhoto']").prettyPhoto({social_tools: false, theme:    'dark_rounded', allow_resize: false});
                        $('.work-panel.image').on('click', function(e) {
                                var img = $(this).find('img').attr('src');
                                var name = $(this).find('h4').text();
                                var desc = $(this).find('p').text();
                                $.prettyPhoto.open(img,name,desc)
                        });
                      $('.img-wrap').hover(function(){
                                      $(this).find('img').addClass("faded");
                              }, function(){
                                      $(this).find('img').removeClass("faded");
                      });
                });
    });
  }
});

You can find the works page with just the caption (to show it works by itself) here: 您可以在此处找到仅带标题的作品页面(以显示其自身的作品):

http://adminref.com/#/works http://adminref.com/#/works

and this is what happens when I add the image fade in: 这就是我添加图像淡入时发生的情况:

http://adminref.com/#/worksfade http://adminref.com/#/worksfade

As you can see it works as expected on the first row but that's it. 如您所见,它在第一行上按预期工作,仅此而已。 Perhaps this is an issue i need to correct on the ember.js level? 也许这是我需要在ember.js级别解决的问题? I have tried adding the fade and comment box box via css both via jquery or one via jquery and the other via css and nothing works on all rows I'm stuck please help. 我已经尝试通过css通过css添加一个淡入淡出和注释框,或者通过jquery添加一个褪色和注释框,而另一个通过css添加任何东西,但在所有被卡住的行上都无效,请帮助。

Well, if I understand well, you try to make a fade in / fade out animation on hover on your projects ? 好吧,据我所知,您尝试在项目上的悬停上制作淡入/淡出动画吗?

Currently, you are adding a class that provides extra styles on hover. 当前,您正在添加一个在悬停时提供额外样式的类。 You'd better do that only with CSS (so it will be easier to manage than javascript events). 您最好仅使用CSS来做到这一点(因此比javascript事件更易于管理)。

Example : 范例:

.panel-image img.panel-image-preview {
  width: 100%;
  border-radius: 2px 2px 0px 0px;
  transition: opacity .2s ease-in-out; /* you may use prefixes */ 
}
.panel-image:hover img.panel-image-preview {
  opacity: .5;
}
.panel-image .img-overlay {
  background-color: #000;

bottom: 0;
color: #fff;
opacity: 0;
filter: alpha(opacity = 0);
position: absolute;
width: 100%;
z-index: 9999;
  transition: opacity .2s ease-in-out; /* you may use prefixes */
}
 .panel-image:hover .img-overlay {
  opacity: 1;
}

I simply added transition on elements that will need a transition on hover and and made style modifications on hover (instead on class you added with javascript). 我只是在需要在悬停上进行过渡的元素上添加了过渡,并在悬停上进行了样式修改(而不是使用javascript添加的类)。 So you'll have to remove the class toggle from your JS code . 因此, 您必须从JS代码中删除类切换

Update : You're obviously encountering a Chrome bug. 更新:您显然遇到了Chrome错误。 Here's a workaround : 这是一种解决方法:

.img-wrap {
overflow: hidden;
position: relative;
-webkit-transform: translate3d(0,0,0); /* this will do the job */
}

Note that it is just a workaround. 请注意,这只是一种解决方法。

Still, I highly recommand to use full CSS solution : smoother, and it surely will be easier to handle and maintain it. 尽管如此,我还是强烈建议您使用完整的CSS解决方案:更流畅,而且肯定会更易于处理和维护。

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

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