屏幕滑动效果

要想让ul下的li一个显示一屏幕,需要让html,body,ul,li的宽度和高度都是100%

下面代码好像有bug,当点击完ol后,用鼠标中轮就不能滚动了呢?
原来是因为 缓动公式 有问题,除不尽,所以就清不了定时器。后面再说!

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        ul,ol{
            list-style-type: none;
        }
        #ul{
            width: 100%;
            height: 100%;
        }
        #ul li{
            width: 100%;
            height: 100%;
            background-color: pink;
        }
        #ol{
            position: fixed;
            top: 0;
            left: 60px;
        }
        #ol li{
            width: 50px;
            height: 50px;
            border: 1px solid #000;
        }
    </style>
    <script src="my.js" type="text/javascript"></script>
    <script>
        window.onload = function () {
            var ulBox = $("ul");
            var ulBoxLi = ulBox.children;
            var olBox = $("ol");
            var olBoxLi = olBox.children;
            var bgColor = ["pink","purple","orange","green","blue"];
            var start = 0,end =0;
            var timer = null;
            for(var i= 0;i<ulBoxLi.length;i++){
                ulBoxLi[i].style.backgroundColor = bgColor[i];
                olBoxLi[i].style.backgroundColor = bgColor[i];
                olBoxLi[i].index = i;
                olBoxLi[i].onclick = function () {
                    clearInterval(timer);
                    end = ulBoxLi[this.index].offsetTop;
                    timer = setInterval(function(){
                        start = start + (end - start)/10;
                        window.scrollTo(0,start);
                    },30);
                }
            }
        }
    </script>
</head>
<body>
<ul id="ul">
    <li>首页</li>
    <li>第二屏</li>
    <li>第三屏</li>
    <li>第四屏</li>
    <li>第五屏</li>
</ul>
<ol id="ol">
    <li>首页</li>
    <li>第二屏</li>
    <li>第三屏</li>
    <li>第四屏</li>
    <li>第五屏</li>
</ol>
</body>
</html>
qt 滑屏翻页效果C++程序 #ifndef PICTUREFLOW_H #define PICTUREFLOW_H #include class PictureFlowPrivate; /*! Class PictureFlow implements an image show widget with animation effect like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form of slides, one main slide is shown at the center with few slides on the left and right sides of the center slide. When the next or previous slide is brought to the front, the whole slides flow to the right or the right with smooth animation effect; until the new slide is finally placed at the center. */ class PictureFlow : public QWidget { Q_OBJECT Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize) Q_PROPERTY(int slideCount READ slideCount) Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex) public: enum ReflectionEffect { NoReflection, PlainReflection, BlurredReflection }; /*! Creates a new PictureFlow widget. */ PictureFlow(QWidget* parent = 0); /*! Destroys the widget. */ ~PictureFlow(); /*! Returns the background color. */ QColor backgroundColor() const; /*! Sets the background color. By default it is black. */ void setBackgroundColor(const QColor& c); /*! Returns the dimension of each slide (in pixels). */ QSize slideSize() const; /*! Sets the dimension of each slide (in pixels). */ void setSlideSize(QSize size); /*! Returns the total number of slides. */ int slideCount() const; /*! Returns QImage of specified slide. */ QImage slide(int index) const; /*! Returns the index of slide currently shown in the middle of the viewport. */ int centerIndex() const; /*! Returns the effect applied to the reflection. */ ReflectionEffect reflectionEffect() const; /*! Sets the effect applied to the reflection. The default is PlainReflection. */ void setReflectionEffect(ReflectionEffect effect); public slots: /*! Adds a new slide. */ void addSlide(const QImage& image); /*! Adds a new slide. */ void addSlide(const QPixmap& pixmap); /*! Sets an image for specified slide. If the slide already exists, it will be replaced. */ void setSlide(int index, const QImage& image); /*! Sets a pixmap for specified slide. If the slide already exists, it will be replaced. */ void setSlide(int index, const QPixmap& pixmap); /*! Sets slide to be shown in the middle of the viewport. No animation effect will be produced, unlike using showSlide. */ void setCenterIndex(int index); /*! Clears all slides. */ void clear(); /*! Shows previous slide using animation effect. */ void showPrevious(); /*! Shows next slide using animation effect. */ void showNext(); /*! Go to specified slide using animation effect. */ void showSlide(int index); /*! Rerender the widget. Normally this function will be automatically invoked whenever necessary, e.g. during the transition animation. */ void render(); /*! Schedules a rendering update. Unlike render(), this function does not cause immediate rendering. */ void triggerRender(); signals: void centerIndexChanged(int index); protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent* event); void mousePressEvent(QMouseEvent* event); void resizeEvent(QResizeEvent* event); private slots: void updateAnimation(); private: PictureFlowPrivate* d; }; #endif // PICTUREFLOW_H
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值