实现图片滚动

本文介绍了一个使用HTML、CSS和JavaScript实现的滚动图片效果案例。通过Velocity.js库来平滑滚动到指定图片,并利用jQuery简化DOM操作。底部导航点用于指示当前图片位置并允许用户跳转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简要截图:

 简要代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>滚动图片效果展示</title>
    <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
    <script src="http://cdn.bootcss.com/velocity/1.2.3/velocity.js"></script>
    <style type="text/css">
       div:not(:last-of-type){
           width:80%;height:750px;margin:0 auto;
       }
       div:first-of-type{background:url(imgs/1.jpg);background-size:cover;}
       div:nth-of-type(2){background:url(imgs/2.jpg);background-size:cover;}
       div:nth-of-type(3){background:url(imgs/3.jpg);background-size:cover;}
       div:nth-of-type(4){background:url(imgs/4.jpg);background-size:cover;}
       div:nth-of-type(5){background:url(imgs/5.jpg);background-size:cover;}
       div:nth-of-type(6){background:url(imgs/6.jpg);background-size:cover;}
       div:nth-of-type(7){background:url(imgs/7.jpg);background-size:cover;}
       div:last-of-type{position:fixed;top:130px;right:50px;}
       div:last-of-type ul{list-style:none;}
       div:last-of-type ul li{width:30px;height:30px;background:black;margin:3px;color:white;text-align:center;line-height:30px;}
        div:last-of-type ul li:hover {cursor:pointer; }
     
    </style>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div>
        <ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li></ul>
    </div>
</body>
</html>
<script type="text/javascript">
    $("div:last ul li").click(function () {
        var numLi = $(this).text();
        $("div:last ul li").css({ "background-color": "black", "color": "white" });//每次都对所有的li背景色进行初始化,点击哪个改变哪个li的背景颜色和字体颜色
        switch (numLi) {
            case "1": $("div:first").velocity("scroll", { duration: 300 }); $(this).css({"background-color":"white","color":"black"});break;
            case "2": $("div:eq(1)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;
            case "3": $("div:eq(2)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;
            case "4": $("div:eq(3)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;
            case "5": $("div:eq(4)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;
            case "6": $("div:eq(5)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;
            case "7": $("div:eq(6)").velocity("scroll", { duration: 300 }); $(this).css({ "background-color": "white", "color": "black" }); break;

        }
    });
 
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值