Javascript 到达锚定标签时如何启动功能
像这样的 这只是一个可以应用于代码的通用示例(因为我无法访问您的完整代码)Javascript 到达锚定标签时如何启动功能,javascript,jquery,function,Javascript,Jquery,Function,像这样的 这只是一个可以应用于代码的通用示例(因为我无法访问您的完整代码) $(文档).ready(函数(){ var-scollH=0; var aH=$('.special').position().top; 控制台日志(aH); $(文档).on('scroll',function(){ scrollH=$(文档).scrollTop(); console.log(scrollH); 如果(滚动H>aH){ 警报(“我击中/越过了特殊锚定标签”); } }); }); 特殊锚上面的其他内容
$(文档).ready(函数(){
var-scollH=0;
var aH=$('.special').position().top;
控制台日志(aH);
$(文档).on('scroll',function(){
scrollH=$(文档).scrollTop();
console.log(scrollH);
如果(滚动H>aH){
警报(“我击中/越过了特殊锚定标签”);
}
});
});
特殊锚上面的其他内容
希望这有帮助 你能为你所说的内容提供一个演示(JSFIDLE)吗?你的问题是,当通过向下滚动页面到达特定的锚定标记时,如何触发特定的功能?这正是我的意思。这有意义吗?没错。这会引起警报。那么我能用我自己的函数替换吗?谢谢你的帮助!!
(function start (){
$('.bar').each(function(i){
var $bar = $(this);
$(this).append('<span class="count"></span>')
setTimeout(function(){
$bar.css('width', $bar.attr('data-percent'));
}, i*100);
});
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).parent('.bar').attr('data-percent')
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now) +'%');
}
});
});
}, 500)
<div class="bar cf" data-percent="100%"><span class="jacklabel"></span><span class="new_labels">SEO</span></div></div>
@mixin transition($transition-property, $transition-time, $method) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-ms-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}
.jackwrap {
width: 100%;
margin: 0 auto;
}
.bar: nth-child(3n+3) {
color: #ccc;
}
.bar {
padding-top: 5px;
border: 1px solid white;
background:#5b83d5;
width: 0px;
height: 35px;
margin: .25em 0;
color: #FFF;
transition:width 2s, background .2s;
-webkit-transform: translate3d(0,0,0);
&:nth-of-type(2n) {
background:lighten(#dadada , 10% );
}
.label {
font-size: 0.75em;
width: 8em;
display: inline-block;
z-index: 1;
font-weight: bold;
&.light {
background:lighten(#3d3d3d , 10% );
}
}
}
.count {
position: absolute;
right: 0.25em;
top: 0.75em;
padding: 0.15em;
font-size: 0.75em;
font-weight: bold;
font-family: $fontSans;
padding-top: 0px;
}
.new_labels {
padding-left: 5px;
padding-top: 5px;
margin-top: 5px;
}
#keep-it-left {
text-align: left;
}
$(document).ready(function() {
var scollH = 0;
var aH = $('.special').position().top;
console.log(aH);
$(document).on('scroll', function() {
scrollH = $(document).scrollTop();
console.log(scrollH);
if (scrollH > aH) {
alert('i hit/am past the special anchor tag');
}
});
});
<div class="content">Other content above special anchor</div>
<a href="#" class="special">This is my Special Anchor Tag</a>