ScrollLeft()不适用于Firefox [英] ScrollLeft() not working with Firefox

查看:95
本文介绍了ScrollLeft()不适用于Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个jsfiddle- http://jsfiddle.net/stevea/DyfGp/2/-外框包含一个从视口伸出的内框.这会强制显示水平滚动条.

I have a jsfiddle here - http://jsfiddle.net/stevea/DyfGp/2/ - where an outer box contains an inner box that extends out of the viewport. This forces a horizontal scroll bar to appear.

A走开 滚动"按钮将读取当前的左滚动,而设置左滚动为20"按钮会将左滚动设置为20.这一切都可以像我在Chrome和Safari上所期望的那样进行:最初选择获取左滚动"会返回0,因为没有丢失任何内容.如果我通常将滚动条移动了一些,选择获取左滚动"将返回我滚动的数量,因为现在该数量从左端丢失了.如果选择设置左滚动为20",则滚动将移动20,然后现在,左端丢失了20px.太好了!

A "Get Left Scroll" button reads the current left scroll and a "Set Left Scroll to 20" button sets the left scroll to 20. This all works as I would expect on Chrome and Safari: Initially selecting Get Left Scroll returns 0 because nothing is missing off the left end. If I maually move the scroll bar some, selecting Get Left Scroll returns the amount I've scrolled, because now this amount is missing off the left end. If is select "Set Left Scroll to 20" the scroll moves 20 and 20px are now missing off the left end. Excellent!

问题在于,这一切在Firefox中均不起作用.在Firefox中,所有滚动读取都返回为0,写滚动似乎没有任何作用.有谁知道可能是什么问题?

The problem is that none of this works in Firefox. In Firefox all the scroll reads come back as 0 and writing a scroll doesn't seem to do anything. Does anyone know what the problem might be?

谢谢

 $('#getScroll').click(function() {

        var bodyscroll = $('body').scrollLeft();
        $('#scroll').html("left scroll is " + bodyscroll);

    });

    $('#setScroll').click(function() {
        $('body').scrollLeft(20);
        var bodyscroll = $('body').scrollLeft();
        $('#scroll').html("left scroll is " + bodyscroll);
    });

推荐答案

scrollLeft放在window而不是body上.

var windowscroll = $(window).scrollLeft();

http://jsfiddle.net/DyfGp/5/

这篇关于ScrollLeft()不适用于Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆