- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个元素,它可以来回摇晃并变小,然后在单击时重置为其原始大小。问题是,当点击时,它似乎经历了尺寸循环,但在第一个之后,它就不再晃动了。如果尝试到处移动功能,但似乎没有任何效果。我的代码中是否存在导致此问题的错误?
var rotated = false;
var height = 24.6;
var width = 15
var points = 0;
function cl() {
width = width / 1.1;
height = height / 1.1;
}
function clicked() {
document.getElementById('box').onclick = function() {
var div = document.getElementById('box'),
deg = rotated ? 0 : 30;
div.style.webkitTransform = 'rotate(' + deg + 'deg)';
div.style.mozTransform = 'rotate(' + deg + 'deg)';
div.style.msTransform = 'rotate(' + deg + 'deg)';
div.style.oTransform = 'rotate(' + deg + 'deg)';
div.style.transform = 'rotate(' + deg + 'deg)';
setInterval(res, 140);
}
}
function res() {
var div = document.getElementById('box'),
deg = rotated ? 0 : 0;
div.style.webkitTransform = 'rotate(' + deg + 'deg)';
div.style.mozTransform = 'rotate(' + deg + 'deg)';
div.style.msTransform = 'rotate(' + deg + 'deg)';
div.style.oTransform = 'rotate(' + deg + 'deg)';
div.style.transform = 'rotate(' + deg + 'deg)';
}
setInterval(gamerule, 10);
function gamerule() {
var div = document.getElementById('box');
div.style.width = width + "%";
div.style.height = height + "%";
if (width < 1) {
width = 15;
height = 24.6;
document.getElementById("cont").style.pointerEvents = "none";
setInterval(ser, 1000);
points++;
function ser() {
document.getElementById("cont").style.pointerEvents = "all";
}
}
}
body {
background-color: #ccc;
}
#cont {
width: 90%;
height: 104%;
background-color: white;
position: absolute;
left: 65px;
top: -30px;
}
#box {
background-color: black;
width: 15%;
height: 24.6%;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
position: absolute;
top: 35.7%;
left: 41.7%;
}
<div id="cont" onclick="cl()">
<div id="box" onclick="clicked()">
</div>
</div>
最佳答案
看起来你有一堆垃圾代码,所以我删除了它。此外,您还使用了 setInterval 而不是 setTimeout。
var rotated = false;
var height = 24.6;
var width = 15
var points = 0;
document.querySelector("#box").addEventListener("click", clickFunction);
// Call this function to simulate the click
function clickFunction() {
width = width / 1.1;
height = height / 1.1;
var div = document.getElementById("box"),
deg = rotated ? 0 : 30;
div.style.webkitTransform = "rotate("+deg+"deg)";
div.style.mozTransform = "rotate("+deg+"deg)";
div.style.msTransform = "rotate("+deg+"deg)";
div.style.oTransform = "rotate("+deg+"deg)";
div.style.transform = "rotate("+deg+"deg)";
// You had set Interval I changed it to setTimeout
setTimeout(res, 140);
}
function res() {
var div = document.getElementById("box"),
deg = rotated ? 0 : 0;
div.style.webkitTransform = "rotate("+deg+"deg)";
div.style.mozTransform = "rotate("+deg+"deg)";
div.style.msTransform = "rotate("+deg+"deg)";
div.style.oTransform = "rotate("+deg+"deg)";
div.style.transform = "rotate("+deg+"deg)";
}
setInterval(gamerule, 10);
function gamerule() {
var div = document.getElementById("box");
div.style.width = width + "%";
div.style.height = height + "%";
if (width < 1) {
width = 15;
height = 24.6;
document.getElementById("cont").style.pointerEvents = "none";
setInterval(ser, 1000);
points++;
function ser() {
document.getElementById("cont").style.pointerEvents = "all";
}
}
}
body{
background-color:#ccc;
}
#cont{
width:90%;
height:104%;
background-color:white;
position:absolute;
left:65px;
top:-30px;
}
#box{
background-color:black;
width:15%;
height:24.6%;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
position:absolute;
top:35.7%;
left:41.7%;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Clicker</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="cont">
<div id="box">
</div>
</div>
<script src="script.js"></script>
</body>
</html>
关于javascript - "Shaking Effect"仅持续一个周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429801/
我刚刚开始了解@ngrx/store 和@ngrx.effects,并在我的Angular/Ionic 应用程序中创建了我的第一个效果。它第一次运行正常,但如果我再次将事件发送到商店(即再次单击按钮时
是否可以将所有自定义表达式保存在外部 .jsx 文件中,以便我可以从项目内部调用它们? 例如,假设我有一个我经常使用的表达式,它将人偶工具指向一个空对象的位置。我知道我可以将该表达式转换为一个可以接受
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 6 年前。 Improve
谁能帮我指出正确的方向,如何在位图上使用这些 Android 4.0 以来可用的 GPU 加速效果? 文档指出例如“它们必须绑定(bind)到 GL_TEXTURE_2D 纹理图像”。但最好的方法是什
我有一个带有背景图像的大 UIButton,上面有五个小的不可见 UIButton。我想在按下一个不可见的小按钮时触发大按钮的突出显示效果。我怎样才能做到这一点? 请帮忙。非常感谢! 最佳答案 为所有
function* rootSaga() { yield all(sagas.map(saga => fork(saga))); } sagaMiddleware.run(rootSaga);
您好,我在将 Li 设置为事件选项卡时遇到问题,我已经添加了悬停效果但是如何添加事件选项卡?。我使用 Angular 的 ng-show 和 ng-hide 来更改 li 中的图标。这是我的代码
我已经将 redux-saga 升级到最新的 0.15.x 版本,并且我已经在 [...effects] 方面解决了很多弃用问题,取而代之的是 all([.. .effects]), 请更新你的代码
我试图理解在组件函数中产生副作用与在没有传入依赖项数组的效果中产生副作用(因此应该在每次渲染时触发)之间的实际区别。据我观察,它们都以相同的频率运行。我意识到效果允许在适当的时间进行清理,但我只是对清
当谈到排队 jQuery Effects 和 jQuery UI Effects 时,我真的很困惑。当我这样做时 $('#div_id').effect('bounce').effect('shake
我正在制作故障文字效果,效果非常好。 现在我正在尝试创建一个书写效果,效果也非常好! 但是两者一起都有一个小错误。 当我将鼠标悬停在文本上时,毛刺效果起作用,但是当书写效果向文本添加一个字母时,这个字
相关,但不是修复:jQuery issue - # has no method 当我尝试在 jquery 中使用 effect 函数时,出现错误 Object [object Object] has
我有一个具有四个 ngrx 操作的 Angular (2) 应用程序: 开始 不被 reducer 处理(没有状态变化) ngrx Effect 调用异步任务并映射到 SUCCESS 或 ERROR
在第16项:“使const成员函数线程安全”中有一段代码如下: class Widget { public: int magicValue() const { std::lock
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
下一行中的最后一行继续生成“警告 C4552:'<=':运算符无效;预期运算符有副作用”错误,但我没有看到任何错误... void countDays(void) { int i=0; if (bir
当我在列表框中使用滚动查看器时,当我通过触摸滚动到达列表框的末尾时,我的整个窗口都在弹跳。当我使用鼠标滚轮时,此行为不会出现。我怎样才能禁用这种过度滚动/橡皮筋效果/回弹效果/弹跳效果。 我在 Win
第 3.5.4 节讨论了有效不可变对象(immutable对象),也就是说,一旦一个对象被安全且完整地构建,它的状态就不会被任何代码路径的任何代码改变。 Goetz 爵士举了一个例子: For exa
我有一部电影在后期效果中没有背景的关键颜色,但背景仍然是静止的。 我想检测在静止背景前行走的 2 个人的运动并将他们带到前面,这样我就可以在背景上创建效果。 那有可能吗?我使用女巫效果吗? 最佳答案
在基于类的组件中: componentDidMount() { axios.get('https://jsonplaceholder.typicode.com/posts').then((re
我是一名优秀的程序员,十分优秀!