jquery左右滑动效果的实现

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jquery左右滑动效果的实现</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#bta").click(function () {
                $("#unit").css("left", "300px");
                document.getElementById("unit").style.left = "300px";
                //                var container = document.getElementById("unit");
                //                try {
                //                    container.insertBefore(container.lastChild, container.firstChild)
                //                }
                //                catch (e) { alert(e); }
                $("#unit").prepend($("#unit>div:last"));
                $("#unit").animate({ "left": 0 }, 500);
                //$("#unit").stop(true, false).animate({ "left": 0 }, 500); 

            });
            $("#btb").click(function () {
                $("#unit").animate({ "left": -300 }, 500);
                //$("#unit").stop(true, false).animate({ "left": -300 }, 500);

                function gundong() {
                    $("#unit").css("left", "0px");
                    //document.getElementById("unit").style.left = "0px";
                    $("#unit").append($("#unit>div:first"));
                    //                                        var container = document.getElementById("unit");
                    //                                        try {
                    //                                            container.appendChild(container.firstChild);
                    //                                        }
                    //                                        catch (e) { alert(e); }
                }//等待动画滚动后执行
                setTimeout(function () { gundong() }, 700);
            })
        });

    </script>
    <style type="text/css">
        *
        {
            padding: 0;
            margin: 0;
        }
        #box
        {
            width: 300px;
            height: 150px;
            margin-bottom: 50px;
            position: relative;
            overflow: hidden;
        }
        #unit
        {
            width: 1200px;
            position: absolute;
        }
        #unit div
        {
            float: left;
            width: 300px;
            height: 150px;
        }
        #bga
        {
            background-color: #F30;
        }
        #bgb
        {
            background-color: #F90;
        }
        #bta, #btb
        {
            float: left;
            width: 50px;
            padding-right: 50px;
            color: #FFF;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div style="width: 800px; height: 300px; padding-top: 100px; background-color: #999;
        margin: 0 auto;">
        <div id="box">
            <div id="unit">
                <div id="bga">
                    框一</div>
                <div id="bgb">
                    框二</div>
                <div id="bgc">
                    框三</div>
                <div id="bgd">
                    框四</div>
            </div>
        </div>
        <div id="bta"></div>
        <div id="btb"></div>
    </div>
</body>
</html>

 

转载于:https://www.cnblogs.com/elves/p/3503595.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值