简体   繁体   English

智能手机的CSS3转换不起作用

[英]CSS3 transform for smartphone don't work

I use the css3 method transform: rotateY(-180deg); 我使用css3方法transform: rotateY(-180deg); for display the content when the curser is hover the block. 用于在光标悬停在块上时显示内容。

我的街区

When i click on the block with my smartphone, nothing append, how can i display the content ? 当我用智能手机单击图块时,没有任何附加内容,如何显示内容?

My class : 我的课 :

#effect-2 figure .img-hover {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0 10px;
    text-align: center;
    background-color: #e74c3c;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    -ms-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: rotateY(-180deg);
    -moz-transform: rotateY(-180deg);
    -ms-transform: rotateY(-180deg);
    -o-transform: rotateY(-180deg);
    transform: rotateY(-180deg);
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
    -ms-transition: all 0.5s;
    -o-transition: all 0.5s;
    transition: all 0.5s;
}

HTML block : HTML块:

<li>
    <figure>
        <img src="img/cocacola.png" class="front">
        <div class="img-hover">
            <h4>Cocacola</h4>
        </div>
    </figure>
</li>

You can add a touch event for touch devices using javascript to add you class (and trigger the animation), ie: 您可以使用javascript为触摸设备添加触摸事件,以添加您的课程(并触发动画),即:

var myElement = //get your element

myElement.addEventListener('touchstart', function(e){
    this.className = "hover";
    setTimeout(function(){
        myElement.className = "";
    }, [animation duration]);
});

You'd set the above animation duration to match the time of your css effects (assuming they don't loop) so that it can be reused. 您可以将上述animation duration设置为与CSS效果的animation duration相匹配(假设它们不循环),以便可以重复使用它。 if it does loop then you don't need to worry about it. 如果它确实循环了,那么您不必担心。

If you want something to work as long as the touch is active, you can trigger the removal of the class on touchend 如果你想,只要触摸是积极的东西的工作,你可以触发取消对类的touchend

Try this code: 试试这个代码:

-ms-transform: rotateY(-180deg); /* IE 9 */
-webkit-transform: rotateY(-180deg); /* Chrome, Safari, Opera */
transform:rotateY(-180deg);

Listen to the click event for the given element and toggle a css-class on it. 侦听给定元素的click事件,并在其上切换一个CSS类。 Then you can specify your transformation in that class. 然后,您可以在该类中指定转换。

An example is to write your event listener inline on the element like this: 一个示例是在这样的元素上内联编写事件侦听器:

<div onclick="this.classList.toggle('transform-class')"></div>

Then later you can if you want refactor your code and bind an event listener in a separate javascript-file. 然后,如果您想重构代码并将事件侦听器绑定到单独的javascript文件中,则可以。

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

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