如何使框架不可滚动

How can I make a frame unscrollable?

本文关键字:滚动 框架 何使      更新时间:2023-09-26

即使滚动是"否",溢出也是隐藏的,浏览器不显示滚动等,但我可以通过鼠标中键滚动。我希望用户无论如何都无法滚动。此外,框架集具有:rows="50,*",并且框架内的内容再次不高于 50 高度像素,它可以滚动几个像素。

在 iframe 中添加以下代码:

$(document).on('mousewheel keydown', function (event) {
    //if the mousewheel event is being fired or if a keydown event with one of the blacklisted keycodes
    if (event.type == 'mousewheel' || event.which in { 40 : 0, 38 : 0, 104 : 0, 98 : 0, 32 : 0 }) {
        //then prevent the scroll from occuring
        return false;
    }
});​​​

这是一个演示:http://jsfiddle.net/9Z2ru/

我尝试通过为 scroll 事件return ing false来禁用滚动,但无法以这种方式禁用(至少在 Chrome 18 中,尽管我怀疑大多数(如果不是全部)浏览器是相同的)。