简体   繁体   English

不能让我的Javascript在本地计算机上正常运行?

[英]Cant get my Javascript to run properly on local machine?

I am using some Javascript that is suppose to appear a certain id when you scroll to a certain point, it works and appears but when you scroll back up it doesn't stay rather it disappears. 我正在使用一些Javascript,当您滚动到某个点时,它会出现一个特定的id,它可以工作并出现,但是当您向上滚动时,它不会停留而是消失。

Here is the Jsfiddle where it works - http://jsfiddle.net/rkerswell/jrpof73y/1/ 这是它起作用的Jsfiddle- http://jsfiddle.net/rkerswell/jrpof73y/1/

And where it doesn't? 而在哪里呢? - http://jsfiddle.net/rkerswell/t18m2tds/ -http://jsfiddle.net/rkerswell/t18m2tds/

Before you ask, I have copied the working code across above but that doesn't work. 在您问之前,我已经在上面复制了工作代码,但是那没用。 So if there is way to get it working using the second Jsfiddle then it should work. 因此,如果有使用第二个Jsfiddle使其工作的方法,则它应该工作。 Any ideas? 有任何想法吗?

This is also the Javascript as it is in my JS file. 这也是我的JS文件中的Javascript。

$(function(){

    var startY = 300;

    $(window).scroll(function(){
        checkY();
    });

    function checkY(){
        if( $(window).scrollTop() > startY ){
            $('#sketch-progress, #photoshop-progress, #illustrator-progress, #indesign-progress, #css-progress, #html-progress, #mac-progress, #windows-progress').slideDown();
        }
        else{
            $('#sketch-progress, #photoshop-progress, #illustrator-progress, #indesign-progress, #css-progress, #html-progress, #mac-progress, #windows-progress').slideUp();
        }
    }

    checkY();

});

It is just when it scrolls back up that I am having the problem. 只是当它向上滚动时,我才遇到问题。 Anything im missing? 我有什么想念的吗?

My assumption here is that you want the animation to remain after scrolling up. 我的假设是,您希望动画在向上滚动后保留。 To do that, let's take a look at your code. 为此,让我们看一下您的代码。

$(function(){

//  Define the height the loading bar should appear at
var startY = 300;

//  Run this function whenever you scroll
$(window).scroll(function(){
    checkY();
});

//  The function ran when scrolling
function checkY(){
    //  If the window position is greater than the preset height
    if( $(window).scrollTop() > startY ){
        //  Make all of these ids slide down
        $('#sketch-progress, #photoshop-progress, #illustrator-progress, #indesign-progress, #css-progress, #html-progress, #mac-progress, #windows-progress').slideDown();
    //  If the window position isn't greater
    } else {
        //  Make all of these ids slide back up
        $('#sketch-progress, #photoshop-progress, #illustrator-progress, #indesign-progress, #css-progress, #html-progress, #mac-progress, #windows-progress').slideUp();
    }
}

//  Run this function again?
//  Not really needed with the scroll function
checkY();

});

tl;dr As you can see, the else statement in that function removes your loading icon if your if statement isn't true. tl; dr如您所见,如果if语句不正确,则该函数中的else语句将删除加载图标。 So, if you want it to stay and only appear once, all you have to do is remove the else in the if statement. 因此,如果您希望它保留并只出现一次,那么您要做的就是删除if语句中的else

Was that what you wanted to know? 那是你想知道的吗?

//  Try this in place of your original checkY function
function checkY(){
    if( $(window).scrollTop() > startY ){
        $('#sketch-progress, #photoshop-progress, #illustrator-progress, #indesign-progress, #css-progress, #html-progress, #mac-progress, #windows-progress').slideDown();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM