1

我试图在每次点击后增加滚动顶部并为此编写它,但它只是第一次工作。在 x 的每个调用值是 30 时,我该如何解决?

我在 w3schools 网站上试用它,它在那里工作

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
 $(function () {
        $("#btncl").click(function (e) {
             var x = $("div").scrollTop() + 30;
            $("div").scrollTop(x);

        });
    });
</script>

<body>
<form id="form1" runat="server">
<div style="border: 1px solid black; height: 150px; overflow: auto">
    <ul>
        <li>
            <img width="80px" style="margin-bottom: 5px;" height="70px" alt="" class="img_gallery"
                src="Images_slider/1.jpg" />
        </li>
        <li>
            <img width="80px" style="margin-bottom: 5px;" height="70px" alt="" class="img_gallery"
                src="Images_slider/2.jpg" />
        </li>

    </ul>
</div>
<br>
    <input type="button" value="Return the vertical position of the scrollbar" id="btncl">

</form>
4

3 回答 3

1
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">

或者?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
于 2013-06-05T08:13:33.013 回答
1

尝试类似的东西

$(function () {
    var x = $("div").scrollTop();
    $("#btncl").click(function (e) {
        x += 30;
        $("div").scrollTop(x);
    });
});

或者

$(function () {
    var incr = 0;
    $("#btncl").click(function (e) {
        incr += 30;
        var x = $("div").scrollTop() + incr;
        $("div").scrollTop(x);
    });
});
于 2013-06-05T08:24:31.547 回答
0

似乎对我有用,请参阅以下jsFiddle

html

<div id='abcd' style="border: 1px solid black; height: 150px; overflow: auto">
    <ul>
        <li>
            <img width="80px" style="margin-bottom: 5px;" height="70px" alt="" class="img_gallery"
                src="Images_slider/1.jpg" />
        </li>
        <li>
            <img width="80px" style="margin-bottom: 5px;" height="70px" alt="" class="img_gallery"
                src="Images_slider/2.jpg" />
        </li>

    </ul>
</div>
<br>
    <input type="button" value="Return the vertical position of the scrollbar" id="btncl" />

Javascript

document.body.onclick=function(e){console.log('ok');$('#abcd').scrollTop($('#abcd').scrollTop() +30);}
于 2013-06-05T08:15:41.813 回答