当滚动到指定的位置时,启动功能,如何重置它并重新启动,如果我们再次回到这个位置
When scroll to a specified place, starts the function, how to reset it and start again, if we go back again to this place?
下面,我给出了一个函数的例子,当我们向下滚动到300 pixels
时,该函数会启动动画。
在圆形元素的末端,它们被转换成椭圆形,红色方块出现在右侧。
问题:如果向上滚动到小于300像素的位置,我该如何重置此功能,如果省略到大于300 pixels
的位置,该如何重新开始?
i = 0;
function ring() {
if (i < 1) {
$('.ring').delay(500).animate({ //1
left: 287,
},
500, 'linear');
$('.ring').delay(500).animate({ //2
left: 500,
},
500, 'linear');
$('.ring').delay(500).animate({ //2.1
left: 594,
},
200, 'linear')
};
if (i < 1) {
$('.views-row-1').animate({ //9
width: 140,
top: -14,
boxShadow: "0 0 8px",
},
500);
$('.views-row-1').delay(500).animate({ //9
width: 115,
top: 0,
boxShadow: "0 0 0",
},
500);
$('.views-row-2').delay(1000).animate({ //9
width: 140,
top: -14,
boxShadow: "0 0 8px",
},
500);
$('.views-row-2').delay(500).animate({ //9
width: 115,
top: 0,
boxShadow: "0 0 0",
},
500);
$('.views-row-3').delay(2000).animate({ //9
width: 140,
top: -14,
boxShadow: "0 0 8px",
},
500)
};
return i++;
}
function scr() {
var top = $(window).scrollTop();
if (top > 300) {
ring();
};
}
$(window).scroll(scr);
.views-row-1,
.views-row-2,
.views-row-3 {
display: block;
position: absolute;
top: 15px;
left: 15px;
background: #ccc;
width: 60px;
height: 60px;
border-radius: 50%;
}
.views-row-2 {
left: 100px;
}
.views-row-3 {
left: 185px;
}
.ring {
display: block;
position: absolute;
top: 20px;
background: red;
width: 20px;
height: 20px;
z-index: 4;
}
.parent {
display: block;
position: fixed;
width: 100%;
top: 60px;
}
body {
height: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
Start to scroll down
<div class="parent">
<div class="ring"></div>
<div class="views-row-1"></div>
<div class="views-row-2"></div>
<div class="views-row-3"></div>
</div>
您需要创建一个函数来重置它。你不能让它自动完成。
要做到这一点,只需将views-row-1、views-row-2和ring的值设置为初始状态。
例如,环将左属性再次设置为零,views行-*的宽度将设置为60px,等等。
相关文章:
- jquery试图按名称获取按钮位置
- 我可以获得相对于被点击元素的确切点击位置吗
- 谷歌地图固定位置覆盖
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 循环比赛位置算法
- es6 相当于下划线查找位置
- 我如何创建一个动态地图来显示我们公司的位置
- 当滚动到指定的位置时,启动功能,如何重置它并重新启动,如果我们再次回到这个位置
- 当我们单击所有位置时,下拉菜单关闭
- 我们将 npm 安装的节点模块放在 Meteor 项目中的什么位置
- 我们如何使用类名通过它在 Jquery 中的位置获取第二个元素
- 如果我们单击页面上的任何位置,气泡应该关闭
- 当我们滚动&Div来到Windows中间位置
- 我们可以通过IP地址准确的得到任何设备的位置吗?如果是,哪个是最好的API
- 我们如何获得访问者的位置使用谷歌API
- 当我们从一个弹出窗口移动到另一个弹出窗口时,滚动条的位置不会保留
- 使用history.js,当我们点击后退按钮时,回到相同的滚动位置
- 我们如何修剪文本从任意开始到任意结束位置
- 如何使用.append()和appendTo()将元素添加到我们想要的位置
- 如何知道mousedown事件是否发生在画布中我们想要的位置