当用户单击 Smoothstate 链接时,我正在尝试停止 pace.js 加载。
我想在事件中调用 Pace.stop 平滑滚动,使用忽略设置,但仍然触发事件。
$('.chronology-nav a').click ->
Pace.stop
onStart:
duration: 2000
render: ($container) ->
$container.addClass 'is-exiting'
$('body').removeClass('done')
Pace.stop
好的。所以我找到了一个解决方案,它有点老套,但对于任何为此苦苦挣扎的人来说。我在 onStart 方法上为 smoothstate 添加了一个类,并且在 css 中将进度 div 设置为 display:none
Coffeescript 代码片段
onStart:
duration: 2000
render: ($container) ->
# add the tag that hides pace
$('body').addClass('chronologyStart')
$container.addClass 'is-exiting'
Pace.stop
onProgress:
duration: 0
render: ($container) ->
Pace.stop
$container.hide()
return
onReady:
duration: 0
render: ($container, $newContent) ->
Pace.stop
$container.show()
smoothState.restartCSSAnimations()
$('body').removeClass('chronologyStart')
$container.html $newContent
$container.removeClass 'is-exiting'
return