【问题标题】:Image flipper not reflowing height图像翻转器不回流高度
【发布时间】:2015-11-17 12:00:44
【问题描述】:

不知道如何搜索,所以从头开始提问。

我有一个连续的四个图像块,悬停时会翻转到信息窗格,并带有指向该项目的链接。在移动设备和平板电脑网站上,这会通过两个图像流向两个图像。

我对完整桌面尺寸的外观和效果非常满意,但是除非我为 '.flip-容器'。但是,如果我有一个固定的高度,这意味着整个块没有正确地重排(而且我仍然有一些重叠)。

因此-我的主要问题是如何使“.flip-container”的高度响应其内容?这是在 Magento 中作为静态块运行的。

我遇到的另一个问题是这在 Safari 中确实无法正常工作(尽管在我尝试过的所有其他浏览器中都可以)。本质上,图像的反面仍在显示,信息窗格的阴影也是如此。任何建议表示赞赏。

代码/示例可能更容易解释自己...

非常感谢所有帮助。如果有人需要更多详细信息,请告诉我

实时示例(它是页面中的第二个内容块,有四个书籍封面):http://bit.ly/1Mz2nQ0

这是 HTML:

<div class="featured">
<div class="flip-left">
    <div class="flip-container first-flip" style="margin-left: 0px;">
        <div class="flipper">
            <div class="front"><img alt="Book Title, Author Name" src="{{media url="wysiwyg/HOME/featured/9781785300080.jpg"}}" /></div>
            <div class="back">
                <h3>Book Title</h3>
                <h4>Author Name</h4>
                <h4>&pound;7.99</h4>
                <div class="read-more"><a href="../book-url.html"> <button type="button">Read More</button></a></div>
            </div>
        </div>
    </div>
    <div class="flip-container">
        <div class="flipper">
            <div class="front"><img alt="Book Title, Author Name" src="{{media url="wysiwyg/HOME/featured/9781845029951.jpg"}}" /></div>
            <div class="back">
                <h3>Book Title</h3>
                <h4>Author Name</h4>
                <h4>&pound;7.99</h4>
                <div class="read-more"><a href="../book-url.html"> <button type="button">Read More</button></a></div>
            </div>
        </div>
   </div>
</div>
<div class="flip-right">
<div class="flip-container first-flip">
     <div class="flipper">
         <div class="front"><img alt="Book Title, Author Name" src="{{media url="wysiwyg/HOME/featured/9781845029890.jpg"}}" /></div>
         <div class="back">
             <h3>Book Title</h3>
                <h4>Author Name</h4>
                <h4>&pound;7.99</h4>
                <div class="read-more"><a href="../book-url.html"> <button type="button">Read More</button></a></div>
         </div>
     </div>
</div>
<div class="flip-container" style="margin-right: 0px;">
    <div class="flipper">
        <div class="front"><img alt="Book Title, Author Name" src="{{media url="wysiwyg/HOME/featured/9781845029852.jpg"}}" /></div>
        <div class="back">
            <h3>Book Title</h3>
                <h4>Author Name</h4>
                <h4>&pound;7.99</h4>
                <div class="read-more"><a href="../book-url.html"> <button type="button">Read More</button></a></div>
        </div>
    </div>
</div>
</div>
</div>

还有 CSS:

 * ============================================ *
 * Image Flipper 4-column
 * ============================================ */

.featured {
    padding-top: 25px;
    padding-bottom: 25px;
    font-size:0;
    }

.featured .flip-container img {

    width: 100%;
    box-shadow: 10px 10px 5px #888888;
    }

.flip-left {
    width:50%;
    float: left;
    }

.flip-right {
    width:50%;
    float:right;
    margin-bottom:40px;
    }

.flip-container {
    width: 45.3125%;
    height: 334px;
    display: inline-block; 
    vertical-align: top;
    margin-right: 3.125%;
    margin-left: 3.125%
    }

/* entire container, keeps perspective */
.flip-container {
    perspective: 1000;
    }
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
    transform: rotateY(180deg);
    }

.back {
    width: 100%;
    }

.front {
    width:100%;
    }

/* flip speed goes here */
.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;

   position: relative;
   }

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
    }

/* front pane, placed above back */
.front {
    z-index: 2;
    /* for firefox 31 */
    transform: rotateY(0deg);
    }

/* back, initially hidden pane */
.back {
    transform: rotateY(180deg);
    background-color: $c-dark-grey;
    padding: 20px;
    box-shadow: 10px 10px 5px #888888;
    }

/* Text Styles */

.featured .flipper .back {
    h3 {
        color: white;
       }

    h4 {
        color: $c-gray;
        }
    }

.read-more button {
    max-width: 90%;
    background: $c-button;
    padding: 5px;
    color: white;
    text-transform: uppercase;
    margin-top: 10px;
    border: none;
    }

.read-more button:hover {
    background: $c-button-hover;
    }

/* Media Breakpoint */
@include bp(max-width, $bp-medium) {

    .featured {
        padding-bottom: 0px;
        padding-top: 0px;
        }

    .flip-container {
        width: 46.875%;     
        margin: 0 0 0 0px;
        }

    .flip-left .first-flip {
        margin-right: 6.25%;
        }

    .flip-right .first-flip {
        margin-right: 6.25%;
        }


    .flip-left {
        width: 100%;
        float: none;
        margin-right: 0px;
        margin-bottom: 40px;
        }

    .flip-right {
        width:100%;
        float: none;

        .first {
            margin-left:0px;
            }

        }
    }

.team-wall .flip-right {
    margin-bottom: 0px;
    }

【问题讨论】:

  • 欢迎来到 StackOverflow。恐怕你必须为.flip-container 指定一个固定的高度,因为.front.backposition:absolute,所以包装器-.flipper,不要为它们“保存”一个位置。你可以通过javascript 修复它(如果你必须),我可以帮你解决这个问题。 Safari 使用哪个版本和操作系统?
  • @MoshFeu 谢谢,这让(有点)更有意义。当我删除 .front 和 .back 上的绝对位置,并从 .flip-container 中删除高度时,整个批次都是可回流的,但只有 .back 低于 .front(组合高度)。因此,我需要使用 Javascript 来模拟“位置:绝对”的效果,以便 .back 出现在 .front 后面?非常感谢任何帮助或指示,因为我对 Javascript 没有太多经验。 Safari 版本是版本 9.0.1 (10601.2.7.2),在 OSX Yosemite 10.10.5 上。如果可以的话,我会在主帖中添加一些屏幕截图。

标签: html css magento-1.9


【解决方案1】:

使用 jQuery 的 JavaScript 解决方案。

翻转效果来源:https://davidwalsh.name/css-flip

$('.flipper').each(function() {
  var elem = $(this),
      front = elem.find('.front');
  
  elem.height(front.height());
});
* {
  box-sizing: border-box;  
}

/* entire container, keeps perspective */
.flip-container {
	perspective: 1000;
}
	/* flip the pane when hovered */
	.flip-container:hover .flipper, .flip-container.hover .flipper {
		transform: rotateY(180deg);
	}

.flip-container/*, .front, .back*/ {
	width: 250px;
}

/* flip speed goes here */
.flipper {
	transition: 0.6s;
	transform-style: preserve-3d;

	position: relative;
}

/* hide back of pane during swap */
.front, .back {
	backface-visibility: hidden;

	position: absolute;
	top: 0;
	left: 0;
  
    width:100%;
}

/* front pane, placed above back */
.front {
	z-index: 2;
	/* for firefox 31 */
	transform: rotateY(0deg);
}

/* back, initially hidden pane */
.back {
	transform: rotateY(180deg);
    background-color: #a4a4a4;
    padding: 20px;
    box-shadow: 10px 10px 5px #888888;
    height:100%; /* now, you can set this to 100%, because his parent - .flipper - has height*/
}

img {
  display:block;
  width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
	<div class="flipper">
		<div class="front">
			<img alt="Ursula's Secret, Mairi Wilson" src="http://testsite.itchycoo-education.com/media/wysiwyg/HOME/featured/9781785300080.jpg">
		</div>
		<div class="back">
          <h3>Ursula's Secret</h3>
          <h4>Mairi Wilson</h4>
          <h4>£7.99</h4>
          <div class="read-more"><a href="../ursula-s-secret.html"><button type="button">Read More</button></a></div>
        </div>
	</div>
</div>
<br /><br />

【讨论】:

  • 谢谢!可能看起来是一个非常愚蠢的问题,但是 jQuery 应该去哪里呢?我已经尝试将它放在静态块中的脚本标签中(在上面的 jquery 调用和翻转容器 div 之间,我已经尝试将它放在我文档的 Head 部分,但它似乎没有使用两种情况下的代码?
  • A.我看到您已经引用了 jquery 库,因此您不能(也不需要)添加另一个引用。 B. 你需要用$(document).ready 函数包装代码(不是必须但更好。见-learn.jquery.com/using-jquery-core/document-ready),而不是用script 标签包装它,并将它放在body 标签的末尾。如果你成功了,请告诉我。
  • 好的 - 所以我需要输入 '' 在正文部分的底部?
  • 谢谢。通过在脚本 'code';(function($){ // REST OF CODE HERE // })(jquery)'code' 周围添加以下内容,我有时可以使用它。在 Chrome(桌面和移动)、Opera、Edge 和 Firefox 中,我已经让它工作了,也没有。在 Internet Explorer 中,大小调整工作正常,但没有出现“.back”面板(只是“.front”的从后到前版本)。在 Safari 中,JS 似乎无法正常工作,并且出现了与 Internet Explorer 类似的问题,但是您会在“.back”面板消失之前短暂闪烁,并且“.back”的阴影在一直。有什么解决办法吗?
  • (有时工作而不是,我的意思是,有时高度会设置,而不是其他时间)。最新代码:bit.ly/1Mz2nQ0
猜你喜欢
  • 2017-07-19
  • 1970-01-01
  • 2012-12-10
  • 1970-01-01
  • 1970-01-01
  • 2019-12-02
  • 1970-01-01
  • 2013-07-26
  • 2017-06-24
相关资源
最近更新 更多