我使用网站上的“到顶”箭头移动到顶部,用平滑的滚动.现在它移动到顶部,但没有平稳地移动。
我用来获得平滑卷轴的js是
$(function() {
$('a.page-scroll').bind('click', function(event) {
console.log("scroll");
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');
event.preventDefault();
});
});
BUt它不起作用..。弹琴是https://jsfiddle.net/36m5kp00/
我用过的jquery是,
<script src="scripts/controllers/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
发布于 2017-07-06 06:21:22
使用这个
$(function() {
$('a.page-scroll').bind('click', function(event) {
$("html, body").animate({ scrollTop: 0 }, 1500);
event.preventDefault();
});
});
发布于 2017-07-06 06:26:08
实际上,如果您想要使用自定义简化方法(如),则需要添加jQuery宽松插件。
注: jQuery附带了2种宽松方法,linear
& swing
。参考资料:https://api.jqueryui.com/easings/
在这里您可以从:https://cdnjs.com/libraries/jquery-easing获得
它工作得很好,请在这里查看:https://jsfiddle.net/ashishanexpert/36m5kp00/4/
您的工作代码应该是:
$(window).scroll(function() {
if ($(this).scrollTop()) {
$('#letTop:hidden').stop(true, true).fadeIn();
} else {
$('#letTop').stop(true, true).fadeOut();
}
});
$(function() {
$('a.page-scroll').bind('click', function(event) {
console.log("scroll");
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');
event.preventDefault();
});
});
https://stackoverflow.com/questions/44941093
复制相似问题