图像旋转360度点击
image rotate 360 degree on click
需要开发者的帮助,我使用图像作为菜单。我只是想当我点击图像时,它旋转360度,然后另一个页面打开。我试着这样做。
<style>
.image {
overflow: hidden;
transition-duration: 0.8s;
transition-property: transform;
}
.image:active {
-webkit-transform: rotate(360deg);
}
</style>
html: <img class="image" src="img path">
在这个代码图像旋转是依赖于点击时间,我希望用户只是点击一次图像旋转360度和链接页面显示。但这不是我想要的。我正在使用jqueryMobile和phonegap
您可以将链接url作为数据属性放在图像中:
<img id="theimage" data-linkurl="#page2"src="http://makeameme.org/media/templates/120/grumpy_cat.jpg" alt="" />
当你处理click事件时,
添加动画类。
你添加了一个animationEnd处理程序,当动画完成时触发。使用one()而不是on(),因为您只希望此处理程序触发一次。
在animationEnd处理程序中,删除动画类(以便下次可以再次添加),从data属性中获取url,然后导航到页面。
$("#theimage").on("click", function(){
$(this).addClass("imageRot").one('webkitAnimationEnd mozAnimationEnd oAnimationEnd msAnimationEnd animationend', function () {
$(this).removeClass("imageRot"); //remove anim class
var url = $(this).data('linkurl'); //get url from data-attribute
$( ":mobile-pagecontainer" ).pagecontainer( "change", url); //navigate to page
});
});
对于动画类,我使用了@cracker的旋转动画(谢谢cracker!):
.imageRot {
-webkit-animation:spin 2s ease-in-out;
-moz-animation:spin 2s ease-in-out;
animation:spin 2s ease-in-out;
}
@-moz-keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
}
@-webkit-keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
}
@keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
}
这是一个工作的DEMO
你需要尝试使用
.image {
-webkit-animation:spin 4s ease-in-out; // No more infinite
-moz-animation:spin 4s linear;
animation:spin 4s linear;
}
@-moz-keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
}
@-webkit-keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
}
@keyframes spin {
100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
或
@-webkit-keyframes rotate {
100% { -webkit-transform: rotate(360deg); }
}
.rotate {
-webkit-animation-name: rotate;
-webkit-animation-duration: 4.5s;
-webkit-animation-iteration-count: infinite;
-webkit-transition-timing-function: linear;
}
DEMO1
以及接下来
试一试:
<style>
.image {
overflow: hidden;
-webkit-transition: transform 0.8s;
transition: transform 0.8s;
}
.image:active {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
</style>
您没有在
transition
中包含webkit选项(-webkit-*
)你没有包括一个非webkit选项在
transform
。
因此,无论您使用什么浏览器,都缺少一些东西(transform
或transition
),因此代码不能在任何浏览器上工作。
edit:我注意到这不是你想要的。我不相信仅靠CSS就能做到。如果你愿意,你可以用jQuery:
<script>
$(".image").click(function(){
$(this).addClass("clicked").delay(800).removeClass("clicked");
});
</script>
<style>
.image {
overflow: hidden;
-webkit-transition: transform 0.8s;
transition: transform 0.8s;
}
.image.clicked {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
</style>
HTML
<img src = "some_image.png" alt = "test" class = "rotative" />
CSS .canRotate
{
-webkit-animation: FullRotation 3s ease-out;
-o-animation: FullRotation 3s ease-out;
-ms-animation: FullRotation 3s ease-out;
-moz-animation: FullRotation 3s ease-out;
animation: FullRotation 3s ease-out;
}
@-webkit-keyframes FullRotation
{
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
@-o-keyframes FullRotation
{
from { -o-transform: rotate(0deg); }
to { -o-transform: rotate(360deg); }
}
@-ms-keyframes FullRotation
{
from { -ms-transform: rotate(0deg); }
to { -ms-transform: rotate(360deg); }
}
@-moz-keyframes FullRotation
{
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
@keyframes FullRotation
{
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
JavaScript function RotateOnClickAndOpenPage(classname, url)
{
var elts = document.getElementsByClassName(classname);
for(var i = 0; i < elts.length; ++i)
{
elts[i].onclick = function(){
this.style.className = "canRotate";
var that = this;
setTimeout(function(){
window.open(url);
that.style.className = "cannotRotate";
}, 3000);
};
}
}
// Exemple
RotateOnClickAndOpenPage("rotative", "http://www.google.fr");
相关文章:
- 检测YouTube上的360度视频
- HTML/Javascript-360度图片的路径更改(显示不同的变化)
- 如何使我的功能360度旋转并上下移动
- 我有来自OpenWeatherMap API的风向数据,数据以0到360度表示.我想将其转换为文本格式
- Javascript动画和360度图像
- 如何防止物体在达到完整圆时旋转 360 度
- CSS3 变换从 360 度旋转到 0 度
- 360 度图像旋转指示器
- 360度画布圆弧中的间隙
- 旋转(360度)圆形分区内的文本框动画
- 使用Fabricjs将文本反转到360度
- 将2D画布(图像+文本)应用于3D表面,并进行360度旋转/动画-可以使用HTML5/CSS3/Javascript或F
- Three JS Camera Orientation以180度而不是360度返回值
- 图像旋转360度点击
- 是否有可能在手机浏览器上使用陀螺仪传感器播放360度Html5视频?
- 使用three.js和tween.js以90度增量旋转对象以创建360度循环
- 自动从-9度旋转到9度
- 360°旋转在UIWebView中不起作用
- 顺时针旋转图标360度
- 360度旋转SVG元素没有任何作用