如何使此动画仅在单击时工作
How to make this animation work only when clicked?
我找到了这个很棒的汉堡菜单动画 http://codepen.io/Zaku/pen/vcaFr,我使用了代码,但是当页面加载时按钮处于"循环"状态。
这是JS:
(function() {
var i, resize;
i = setInterval(function() {
return $("div").toggleClass("cross");
}, 1500);
$("div").click(function() {
clearInterval(i);
return $("div").toggleClass("cross");
});
resize = function() {
return $("body").css({
"margin-top": ~~((window.innerHeight - 150) / 2) + "px"
});
};
$(window).resize(resize);
resize();
}).call(this);
我必须更改什么才能使其仅在单击时工作?
谢谢
只需删除 setInterval。
请参阅下面的代码:
(function () {
var resize;
$('div').click(function () {
return $('div').toggleClass('cross');
});
resize = function () {
return $('body').css({ 'margin-top': ~~((window.innerHeight - 150) / 2) + 'px' });
};
$(window).resize(resize);
resize();
}.call(this));
body,
html,
div {
background: #292a38;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
text-align: center;
}
svg {
width: 200px;
height: 150px;
cursor: pointer;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
path {
fill: none;
-webkit-transition: stroke-dashoffset 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25), stroke-dasharray 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25);
-moz-transition: stroke-dashoffset 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25), stroke-dasharray 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25);
-o-transition: stroke-dashoffset 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25), stroke-dasharray 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25);
-ms-transition: stroke-dashoffset 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25), stroke-dasharray 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25);
transition: stroke-dashoffset 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25), stroke-dasharray 0.5s cubic-bezier(0.25, -0.25, 0.75, 1.25);
stroke-width: 40px;
stroke-linecap: round;
stroke: #a06ba5;
stroke-dashoffset: 0px;
}
path#top,
path#bottom {
stroke-dasharray: 240px 950px;
}
path#middle {
stroke-dasharray: 240px 240px;
}
.cross path#top,
.cross path#bottom {
stroke-dashoffset: -650px;
stroke-dashoffset: -650px;
}
.cross path#middle {
stroke-dashoffset: -115px;
stroke-dasharray: 1px 220px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<svg viewBox="0 0 800 600">
<path d="M300,220 C300,220 520,220 540,220 C740,220 640,540 520,420 C440,340 300,200 300,200" id="top"></path>
<path d="M300,320 L540,320" id="middle"></path>
<path d="M300,210 C300,210 520,210 540,210 C740,210 640,530 520,410 C440,330 300,190 300,190" id="bottom" transform="translate(480, 320) scale(1, -1) translate(-480, -318) "></path>
</svg>
</div>
相关文章:
- JavaScript-在手机上不工作的情况下,在外部单击时隐藏元素
- addEventListener的Javascript代码不工作!?(单击时打开放大的img)
- button.单击两次删除附加操作后不工作
- 我该如何阻止单击方法多次工作
- Hammer.js滑动不会'单击按钮后才能工作
- 为什么不'加载$(document.ready(function)后,单击“工作”
- jQuery animate只在单击时工作一次
- 单击'Backbone.js视图'不要工作
- 谷歌工作表中的按钮,当单击时,会更改特定单元格的背景
- 单击水平滚动库中的图像以居中显示无法工作的功能
- 禁用触摸设备上的单击链接未按预期工作
- Chrome扩展程序:浏览器操作单击按钮工作一次
- 单击仅工作一次
- 单击事件在 iPad 中使用 Angularjs 无法正常工作
- 我需要在单击时运行两个函数.即使嵌套在一起,我也无法让它们都工作
- 打开选择之前的事件.(单击工作速度不够快)
- 需要单击以完全执行,然后才能再次单击工作
- 在具有多个链接的ng网格中创建自定义单元格内容-使ng单击工作
- jQuery单击工作一次,而不是两次
- ng-单击“工作不正常”