(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)
我试图找到一种在我的页面上到达锚标记时触发此方法的方法。所有信息都分为一个页面,此图形功能可以动画显示。问题是它位于我的页面下方的#skills锚点上,我希望在到达/看到该锚点时触发动画/功能。
有什么想法? Js / JQ新手。
感谢您的帮助。
<div class="bar cf" data-percent="100%"><span class="jacklabel"></span><span class="new_labels">SEO</span></div></div>
其余的是图条等的CSS。
@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;
}
答案 0 :(得分:0)
它只是一个可以应用于您的代码的一般示例(因为我无法访问您的完整代码)
$(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>
希望这有帮助!