1

This is my code:

$( document ).ready(function() {
    var target = $(".passthis").offset().top-$(window).height();

    $(document).scroll(function() {
        if ($(window).scrollTop() >= target) {
            $(".something").fadeIn(2000);
        }
    });


});

HTML:

<div class="passthis" style="text-align:center;font-size:20px;margin-top:815px;">

        Scroll Below here
    </div>

Right now this code will show div.something only when the user passes div.passthis. The .passthis div is exactly at the bottom of the screen. Howver, I want to move .passthis the middle of the screen but being new to JS i am unsure how i can modify my script to do that. Can I use a number for x,y or something?

Question:

What can I do to move the .passthis to the middle of the screen and still make .something show after the user passes .passthis.

4

1 回答 1

2

这是一个jsFiddle 演示,欢迎您使用。正如我所解释的,如果窗口从不滚动,则什么都不会发生(.something will never come)。此外,您可以在此演示中查看不同值的数字。就数学而言,它应该让您了解您正在拍摄的内容。如上所述,您应该阅读 jQuery.scrollTop()和其他窗口维度的方法和值。

于 2013-07-09T13:13:32.917 回答