【问题标题】:cross browser mouse wheel, to scroll 100% browser height by one single wheel跨浏览器鼠标滚轮,通过一个滚轮滚动 100% 浏览器高度
【发布时间】:2014-08-11 19:46:05
【问题描述】:

有一些js

$(document).ready(function(){
var winHeight = window.innerHeight ?
        function() {
            return window.innerHeight;
        } :
        function() {
            return document.documentElement.clientHeight;
        };
$('.first-block').height(winHeight);
$(window).scroll(function(){

var firstBlockHeight = winHeight();
var scrollTop= $('body').scrollTop();

if (scrollTop > 0 && scrollTop < firstBlockHeight/2 && $('body').hasClass('scrolled') === false) {
$("body")
  .animate({ scrollTop: firstBlockHeight+10 }, 600)
  .addClass('scrolled');

} else if (scrollTop==0) {
$("body")
.animate({ scrollTop: 0 }, 600)
.removeClass('scrolled');
}
 });
 });

通过单个鼠标滚轮滚动第一个块 100% 高度。此代码在 firefox 中不起作用。如果玩滚动游戏会有错误。请帮助解决这个问题并添加跨浏览器支持。 请参阅JsFiddle。

谢谢。

【问题讨论】:

  • 请不要第二次猜测我设置鼠标的方式,我更喜欢我的设置...
  • @dandavis 对不起,我完全听不懂你的意思..
  • 你已经看过这个问题了吗? stackoverflow.com/questions/9471286/…
  • @JaimeGomez 感谢链接,但我看不到循环滚动的错误。
  • @CroaToa 我相信 dandavis 暗示改变用户的滚动行为对你的用户体验来说并不是最好的。

标签: javascript jquery css scroll mousewheel


【解决方案1】:

我使用 mouswheel.js 并且我做到了! :) 可能对某人有用

$(document).ready(function(){
var winHeight = window.innerHeight ?
            function() {
                return window.innerHeight;
            } :
            function() {
                return document.documentElement.clientHeight;
            };
$('.first-block').height(winHeight);
var BlockHeight = $('.first-block').height();
$.browser = {};
$.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) &&     !/webkit/.test(navigator.userAgent.toLowerCase());
if($.browser.mozilla)
{
 var ScrollType = 'html';
  }
else
   {
 var ScrollType = 'body';
  }
$('.first-block').mousewheel(function(event, delta, deltaX, deltaY) {
  if((delta<0) && ($(ScrollType).scrollTop()==0)) $(ScrollType).animate({ scrollTop: BlockHeight-    104 }, 600);
});

$(ScrollType).keydown(function(event){
 if((event.keyCode==40) && ($(ScrollType).scrollTop()==0)) $(ScrollType).animate({ scrollTop:  BlockHeight-104 }, 600);
})

});

感谢我)

【讨论】:

    猜你喜欢
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2014-04-05
    • 1970-01-01
    相关资源
    最近更新 更多