二、原生JS实现优酷会员首页动态切换轮播图

优酷会员首页

一、效果图(完整效果参见源码)

在这里插入图片描述

二、源码

(一)HTML文档(index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>优酷会员首页</title>
    <link rel="stylesheet" href="css/index.css">
    <link rel="icon" href="favicon.ico">
    <base target="_blank">  
</head>
<body>
    <!-- wrapperTop -->
    <div class="wrapperTop">
        <div class="topNavBox">
            <!-- topNav -->
            <div class="topNav clearfix">
                <div class="topNavLeft fl">
                    <a href="#" target="_self" class="logo"><img src="images/youku_vip_logo.png" alt="优酷vip会员"></a>
                    <ul class="list_two">
                        <li>
                            <a href="#"><span class="iconfont icon_01">&#xe613;</span>首页</a>
                        </li>
                        <li>
                            <a href="#"><span class="iconfont">&#xe61c;</span>频道</a>
                        </li>
                    </ul>
                </div>
        
                <div class="topNavRight fr">
                    <ul class="list_four">
                        <li>
                            <a href="#">
                                <span class="iconfont">&#xe710;</span>
                                <p>关注</p>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="iconfont">&#xe506;</span>
                                <p>记录</p>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="iconfont">&#xe657;</span>
                                <p>上传</p>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="iconfont">&#xe60d;</span>
                                <p>客户端</p>
                            </a>
                        </li>
                    </ul>
        
                    <div class="userIcon">
                        <!-- 未登录 -->
                        <!-- <div class="user"><img src="images/user_icon_default.png" alt=""></div> -->

                        <!-- 已登录 -->
                        <div class="user"><img src="images/user_icon.png" alt=""></div>
                        <div class="hg"><img src="images/huangguan_v1.png" alt=""></div>
                    </div>
                </div>
        
                <div class="searchContent">
                    <form action="">
                        <input type="text" name="content">
                        <button type="submit">搜全网</button>
                    </form>
                </div>
            </div>
        </div>
    
        <!-- bannerBox -->
        <div class="bannerBox">
            <!-- banner -->
            <ul class="banner clearfix">
                <li class="show">
                    <a href="#"><img src="images/banner_01.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_02.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_03.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_04.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_05.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_06.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_07.png" alt=""></a>
                </li>
                <li>
                    <a href="#"><img src="images/banner_08.png" alt=""></a>
                </li>
            </ul>

            <!-- bannerNavBox -->
            <div class="bannerNavBox">
                <!-- bannerNav -->
                <ul class="bannerNav clearfix">
                    <li class="active">鹤唳华亭</li>
                    <li>热爱</li>
                    <li>速度与激情:特别行动</li>
                    <li>被点亮的星球</li>
                    <li>漫长的告别</li>
                    <li>演技派片场记</li>
                    <li>大地私宴</li>
                    <li>攀登者</li>
                </ul>
            </div>

            <!-- vipRight -->
            <div class="vipRight">
                <div class="user">
                    <!-- 未登录 -->
                    <!-- <button>立即登录</button> -->

                    <!-- 已登录 -->
                    <div class="userIcon"></div>
                    <div class="userName">Hi stage拼途<img src="images/huangguan_v1.png" alt=""></div>
                    <div class="userVip">VIP会员<span>2019-12-17 到期</span></div>
                </div>

                <div class="info">
                    <div class="title">VIP 会员特权</div>
                    <div class="content">
                        <a href="#">广告特权</a>
                        <a href="#">院线新片</a>
                        <a href="#">尊贵标识</a>
                        <a href="#">独家特供</a>
                    </div>
                </div>

                <div class="pay">
                    <button>立即续费</button>
                </div>
                
                <div class="bottomBox">
                    <a href="#">我的账户</a>
                    <a href="#">激活会员卡</a>
                </div>
            </div>
        </div>
    </div>

    <!-- middlerBar -->
    <div class="middlerBar clearfix">
        <div class="channels fl">
            <div class="title">频道</div>
            <div class="allChannels">
                <div class="channelGroup">
                    <a href="#">电影</a>
                    <a href="#">纪录片</a>
                </div>
                <div class="channelGroup">
                    <a href="#">剧集</a>
                    <a href="#">德云社</a>
                </div>
                <div class="channelGroup">
                    <a href="#">动漫</a>
                    <a href="#">E!ZONE</a>
                </div>
            </div>
        </div>
        <div class="splitBorder fl"></div>
        <div class="tags fl">
            <div class="titleBox">
                <div class="title">分类</div>
                <a href="#">全部></a>
            </div>
            <div class="allTags">
                <div class="tagsGroup">
                    <a href="#">最热</a>
                    <a href="#">恐怖</a>
                </div>
                <div class="tagsGroup">
                    <a href="#" class="stress">最新</a>
                    <a href="#">爱情</a>
                </div>
                <div class="tagsGroup">
                    <a href="#">好评</a>
                    <a href="#">武侠</a>
                </div>
                <div class="tagsGroup">
                    <a href="#">内地</a>
                    <a href="#">犯罪</a>
                </div>
                <div class="tagsGroup">
                    <a href="#">北美</a>
                    <a href="#">悬疑</a>
                </div>
                <div class="tagsGroup">
                    <a href="#">香港</a>
                    <a href="#">惊悚</a>
                </div>
            </div>
        </div>
        <div class="promotion fr">
            <a href="https://v.youku.com/v_show/id_XNDM0OTg1MDAyOA==.html?spm=a2h03.12024492.app.5~5!4~5!4~A&scm=20140693.0-0.444_82448_0.0&descm=20140693.0-0.444_82448_0.0"></a>
        </div>
    </div>

    <!-- hotDrawer -->
    <div class="hotDrawer">
        <div class="basicTitle">
            <div class="drawerTitle"><span>VIP</span>正在热播</div>
            <span class="rightChange">换一换</span>
        </div>

        <div class="hotList clearfix">
            <div class="hotWindow fl">
                <div class="hotPlayWindow">
                    <img src="images/hotList/hotPlayWindow_bg.png" alt="" title="此处待插入视频!">
                </div>
                <ul class="hotPlayList">
                    <li class="hotPlayList_active">鹤唳华亭</li>
                    <li>第二次也很美</li>
                    <li>大明风华</li>
                    <li>漫长的告别</li>
                    <li>热爱</li>
                    <li>蒙面唱将猜猜猜 第四季</li>
                </ul>
            </div>

            <div class="itemListBox fl">
                <div class="itemListOne">
                    <a href="#" class="itemImg"><img src="images/hotList/itemListOne_01.png" alt=""></a>
                    <div class="itemMark">VIP</div>
                    <div class="itemScore"><i>9</i>.9</div>
                    <div class="itemName"><a href="#">归还世界给你</a></div>
                    <div class="itemDisc">杨烁娜扎虐恋情深</div>
                </div>
                <div class="itemListOne">
                    <a href="#" class="itemImg"><img src="images/hotList/itemListOne_02.png" alt=""></a>
                    <div class="itemMark">YIP</div>
                    <div class="itemScore"><i>9</i>.9</div>
                    <div class="itemName"><a href="#">外交风云</a></div>
                    <div class="itemDisc">展现新中国外交历程</div>
                </div>
                <div class="itemListOne">
                    <a href="#" class="itemImg"><img src="images/hotList/itemListOne_03.png" alt=""></a>
                    <div class="itemMark">独播</div>
                    <div class="itemScore"><i>9</i>.9</div>
                    <div class="itemName"><a href="#">叫我僵小鱼 日常篇 第三季 青春鱼你</a></div>
                    <div class="itemDisc">僵小鱼校园奇遇记</div>
                </div>
                <div class="itemListOne">
                    <a href="#" class="itemImg"><img src="images/hotList/itemListOne_04.png" alt=""></a>
                    <div class="itemMark">VIP·半价</div>
                    <div class="itemScore"><i>8</i>.8</div>
                    <div class="itemName"><a href="#">少年的你</a></div>
                    <div class="itemDisc">易烊千玺屏幕首秀</div>
                </div>
            </div>
        </div>
    </div>

    <br>
    <br>
    <br>
    <br>
    <br>

    <script src="js/index.js"></script>
</body>
</html>

(二)CSS文档(index.css)

@import 'reset.css';
@import 'wrapperTop.css';
@import 'middleBar.css';



.hotDrawer {
    height: 395px;
    margin-top: 40px;
}
.hotDrawer .basicTitle {
    width: 1156px;
    height: 40px;
    margin: 0 auto;
}
.hotDrawer .basicTitle .drawerTitle {
    display: inline-block;
    height: 40px;
    line-height: 40px;
    font-size: 28px;
    text-align: left;
    color: #131418;
}
.hotDrawer .basicTitle .drawerTitle span {
    font-size: 30px;
    color: #CCA558;
    margin-right: 3px;
}
.hotDrawer .basicTitle .rightChange {
    float: right;
    margin-top: 20px;
    height: 20px;
    line-height: 20px;
    padding-right: 2px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
}
.hotDrawer .hotList {
    width: 1156px;
    height: 335px;
    margin: 20px auto 0;
}
.hotDrawer .hotList .hotWindow {
    width: 380px;
    height: 335px;
}
.hotDrawer .hotList .hotWindow .hotPlayWindow {
    height: 100%;
    height: 214px;
    border-radius: 4px;
    background-image: url(../images/hotList/hotPlayWindow_bg_pink.png);
    background-size: cover;
    background-position: 0 0;
    background-repeat: no-repeat;
    overflow: hidden;
}
.hotDrawer .hotList .hotWindow .hotPlayWindow img {
    height: 100%;
    height: 100%;
}
.hotDrawer .hotList .hotWindow .hotPlayList {
    height: 100%;
    height: 121px;
    border-radius: 4px;
    background-color: #fff;
}
.hotDrawer .hotList .hotWindow .hotPlayList li {
    float: left;
    width: 147px;
    height: 40px;
    line-height: 40px;
    padding-left: 29px;
    padding-right: 14px;
    background-image: url(../images/hotList/list_disc_icon.png);
    background-size: 5px 5px;
    background-position: 15px 17px;
    background-repeat: no-repeat;
    font-size: 14px;
    color: #303030;
    cursor: pointer;
    border-top: 1px dotted #D8D8D8;

    /* 溢出打点---单行文本 */
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}
.hotDrawer .hotList .hotWindow .hotPlayList li:nth-child(1),
.hotDrawer .hotList .hotWindow .hotPlayList li:nth-child(2) {
    border-top: none;
}
.hotDrawer .hotList .hotWindow .hotPlayList li:hover {
    color: #CCA558;
}
.hotDrawer .hotList .hotWindow .hotPlayList li.hotPlayList_active {
    color: #CCA558;
}

.hotDrawer .hotList .itemListBox {
    width: 776px;
    height: 335px;
}
.hotDrawer .hotList .itemListBox .itemListOne {
    float: left;
    width: 186px;
    height: 335px;
    margin-left: 8px;
    font-size: 0;
    border-radius: 4px;
    background-color: #fff;
}
.hotDrawer .hotList .itemListBox .itemListOne .itemImg {
    display: inline-block;
    width: 186px;
    height: 279px;
    border-radius: 4px;
    overflow: hidden;
}
.hotDrawer .hotList .itemListBox .itemListOne .itemImg img {
    width: 186px;
    height: 279px;
}

.hotDrawer .hotList .itemListBox .itemListOne .itemName {
    display: inline-block;
    max-width: 166px;
    margin-top: 10px;
    padding-left: 10px;
    height: 16px;
    line-height: 16px;
    font-size: 14px;
    font-weight: bold;
    color: #191919;
    cursor: pointer;

    /* 单行文本溢出打点 */
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}
.hotDrawer .hotList .itemListBox .itemListOne .itemName:hover a {
    color: #CCA558;
}
.hotDrawer .hotList .itemListBox .itemListOne .itemDisc {
    max-width: 166px;
    margin-top: 10px;
    padding-left: 10px;
    font-size: 12px;
    line-height: 14px;
    color: #9B9B9B;

    /* 单行文本溢出打点 */
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

(三)JS文档(index.js)

/**
 * 优酷会员首页上下图片菜单联动
 */
var oLi = document.querySelectorAll('.wrapperTop .bannerBox .bannerNavBox .bannerNav li'),
    oImgLi = document.querySelectorAll('.wrapperTop .bannerBox .banner li'),
    nowIndex = 0,
    timer = null;

function init() {
    bindEvent();
    play();
}
init();

//事件函数
function bindEvent() {
    len = oLi.length;
    for(var i = 0; i < len; i++) {
        oLi[i].index = i;
        oLi[i].onmouseenter = function () {
            nowIndex = this.index;
            move(nowIndex);
        }
    }
}

// 自动轮播 每隔一段时间索引值自动变化
function play() {
    clearInterval(timer);
    timer = setInterval(function () {
        nowIndex++;
        if(nowIndex == oLi.length) {
            nowIndex = 0;
        }
        move(nowIndex);
    },6000);
}

// 动作函数
function move(i) {
    var activeLi = document.getElementsByClassName('active')[0];
    activeLi.className = '';
    oLi[i].setAttribute('class', 'active');
    var showImg = document.getElementsByClassName('show')[0];
    showImg.className = '';
    oImgLi[i].setAttribute('class', 'show');
}
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值