我有一个 .js 文档,它允许我在不同页面之间切换到同一个 html 文档中。 我有一个触发按钮,仅在单击时激活转换,我也想在滚动时激活它或仅在滚动时激活它。 我尝试在我的函数中添加 onscroll 参数,但它不起作用。我认为这是因为我的不同页面的宽度为:100%,所以我没有任何滚动条...
这是我的 HTML 结构
<body>
<button id="iterateEffects" class="btn_bot"></button> <!--Trigger btn-->
<div id="pt-main" class="pt-perspective">
<div class="pt-page pt-page-1">First page code inside</div>
<div class="pt-page pt-page-2">Second page code inside</div>
etc...
</div>
</body>
这是我的按钮功能
$iterate = $( '#iterateEffects' ) //my iterateEffects var
function init() {
$pages.each( function() {
var $page = $( this );
$page.data( 'originalClassList', $page.attr( 'class' ) );
} );
$pages.eq( current ).addClass( 'pt-page-current' );
$( '#dl-menu' ).dlmenu( {
animationClasses : { in : 'dl-animate-in-2', out : 'dl-animate-out-2' },
onLinkClick : function( el, ev ) {
ev.preventDefault();
nextPage( el.data( 'animation' ) );
}
} );
$iterate.on( 'click', function() {
animcursor = 3;
nextPage( animcursor );
} ); //Activate the function on click
}
最佳答案
你尝试过这个吗:
$( document ).on( 'scroll', function() {
animcursor = 3;
nextPage( animcursor );
} );
还要确保您的页面可滚动。
关于javascript - 如何编写一个 JS 按钮来激活单击和滚动时的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33721208/