无法在scrollTop

时间:2016-03-12 02:28:19

标签: javascript jquery html css

我会尽可能清楚地解释自己。

我想做什么?

当scrollTop值大于40时,我试图使段落的不透明度为1,并且当scrollTop值小于40时,再次使段落的不透明度为0。(所以基本上当用户向下滚动文本时,当它们再次向上滚动时它会消失);

我的问题是什么?

使用jQuery效果fadeTo("slow", 1),当scrollTop值大于40时,我可以使文本消失。但是,当scrollTop的值小于40时,我无法再次消失。

注意:默认情况下,我将段落的不透明度设置为0。

这是我在codePen上的当前代码的链接 http://codepen.io/kevin1616/pen/reLgQZ

$(window).scroll(function() {
    var scrollPosition = $(this).scrollTop();
    console.log(scrollPosition);
    if (scrollPosition > 40) {
        // apply effects and animations
        $('p').fadeTo("slow",1);
    } else if(scrollPosition < 40){
        // apply effects and animations
        $('p').fadeTo("slow",0);
    }
});

1 个答案:

答案 0 :(得分:0)

希望这可以帮助你!

 #include "opencv2/objdetect/objdetect.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"

 #include <iostream>
 #include <stdio.h>

 using namespace std;
 using namespace cv;

 /** Function Headers */
 void detectAndDisplay( Mat frame);

 /** Global variables */
 String face_cascade_name = "haarcascade_frontalface_alt.xml";
 String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
 CascadeClassifier face_cascade;
 CascadeClassifier eyes_cascade;
 string window_name = "Capture - Face detection";
 RNG rng(12345);
 double fps;

 /** @function main */
 int main( int argc, const char** argv )
 {
    VideoCapture cap("/home/pradeep/Downloads/President Obama Lectures Romney.mp4"); // open the video file for reading
    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the video file" << endl;
         return -1;
    }

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

    fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
    cout << "Frame per seconds : " << fps << endl;
    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
    Size S(dWidth,dHeight);

    while(1)
    {

        Mat frame;
        int skip_frame = 4;
        while(skip_frame)
        {
            bool bSuccess = cap.read(frame); // read a new frame from video
            skip_frame--;
            if (!bSuccess) //if not success, break loop
            {
                cout << "Cannot read the frame from video file" << endl;
                break;
            }
        }

        //-- 3. Apply the classifier to the frame
        if( frame.empty() )
        { printf(" --(!) No captured frame -- Break!"); break; }

        std::vector<Rect> faces;
        Mat frame_gray;

        cvtColor( frame, frame_gray, CV_BGR2GRAY );
        equalizeHist( frame_gray, frame_gray );

        //-- Detect faces
        face_cascade.detectMultiScale( frame_gray, faces, 1.3, 5, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

        for( size_t i = 0; i < faces.size(); i++ )
        {
            Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
            ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

            Mat faceROI = frame_gray( faces[i] );
            std::vector<Rect> eyes;

            //-- In each face, detect eyes
            eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 0, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

            for( size_t j = 0; j < eyes.size(); j++ )
            {
                Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
                int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
            circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
            }
        }
        VideoWriter Video("face_output.avi", CV_FOURCC('M','J','P','G'), fps, S, true);
        if(!Video.isOpened())
        {
            printf("unable to write video file");
        }
        Video.write(frame);
        //-- Show what you got
        imshow( window_name, frame );

        int c = waitKey(10);
        if( (char)c == 'c' ) { break; }
    }
    return 0;
 }

我确信使用切换有更好的解决方案。

http://api.jquery.com/fadein/

http://api.jquery.com/fadetoggle/

相关问题