Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在任何特定Div中滚动打印警报?_Javascript_Jquery_Html_Css_Scroll - Fatal编程技术网

Javascript 如何在任何特定Div中滚动打印警报?

Javascript 如何在任何特定Div中滚动打印警报?,javascript,jquery,html,css,scroll,Javascript,Jquery,Html,Css,Scroll,我想在用户滚动标题时打印警报,基本上我想在滚动特定区域后将标题显示设置为无。现在我想在用户到达内容区域时打印一个警报 我已经写了下面的代码,它不能正常工作。请检查并指导我 jquery $(document).ready(function (e) { $(".container").scroll(function () { alert("Scrolled!"); }); }); html <body> <div id="header"&

我想在用户滚动标题时打印警报,基本上我想在滚动特定区域后将标题显示设置为无。现在我想在用户到达内容区域时打印一个警报

我已经写了下面的代码,它不能正常工作。请检查并指导我

jquery

$(document).ready(function (e) {
    $(".container").scroll(function () {
        alert("Scrolled!");
    });
});
html

<body>
    <div id="header"></div>
    <div class="container">
        <div id="text">This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text This is Random TextThis is Random TextThis is Random TextThis is Random Text</div>
    </div>
    <div class="footer"></div>
</body>

这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本Text这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本这是随机文本

只需在代码中做一点小小的更改

$(".container").bind('mouseover', function() {
            alert("Scrolled!");
            });

    });

其余的都是一样的。

如果你想让它发生在滚动条上

$(window).scroll(function () {
    var offset = $(".container").offset().top;

    if ($(window).scrollTop() >= offset) {
        alert("Scrolled!");
    }
});

但当我使用滚动条向下移动时,它确实会生成任何
alert()
,只要您进入div容器,它就会工作。那意味着你的鼠标在div上。