jq放大商品图,仿京东

git仓库源码地址:https://gitee.com/wyycoing/frontend_practical_demo

git下载: https://gitee.com/wyycoing/frontend_practical_demo.git

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <style>
            * {
                padding: 0;
                margin: 0;
            }

            .w430 {
                width: 430px;
            }

            .fl {
                float: left;
            }

            .w {
                width: 100%;
            }

            .h {
                height: 100%;
            }

            img {
                border: 0;
                vertical-align: middle;
            }

            .jqzoom {
                width: 100%;
                height: 100%;
                float: left;
                border: none;
                position: relative;
                padding: 0px;
                cursor: pointer;
                margin: 0px;
                display: block;
                text-align: center;
            }

            .spec-scroll {
                clear: both;
                margin-top: 20px;
                width: 100%;
            }

            .spec-scroll .prev,
            .spec-scroll .next {
                color: #DA3131;
                display: block;
                width: 13px;
                height: 72px;
                line-height: 72px;
                cursor: pointer;
                text-decoration: none;
            }

            .spec-scroll .next {
                float: right;
            }

            .y_pore {
                position: relative;
            }

            .spec-scroll .prev {
                float: left;
                margin-right: 4px;
            }

            .spec-scroll .next {
                float: right;
            }

            .f28 {
                font-size: 28px;
            }

            .spec-scroll .items {
                float: left;
                position: relative;
                width: 399px;
                height: 86px;
                overflow: hidden;
            }

            .spec-scroll .items ul {
                position: absolute;
                width: 999999px;
                height: 100%;
            }

            ol,
            ul {
                list-style: none;
            }

            .spec-scroll .items ul li {
                float: left;
                width: 80px;
                text-align: center;
            }

            .spec-scroll .items ul li img {
                border: 1px solid #E9E9E9;
                width: 72px;
            }

            .h430 {
                height: 430px;
            }

            .jqzoom {
                width: 100%;
                height: 100%;
                float: left;
                border: none;
                position: relative;
                padding: 0px;
                cursor: pointer;
                margin: 0px;
                display: block;
                text-align: center;
            }

            .zoomdiv {
                z-index: 100;
                position: absolute;
                top: 0px;
                left: 0px;
                width: 350px;
                height: 350px;
                background: #ffffff;
                border: 1px solid #CCCCCC;
                display: none;
                text-align: center;
                overflow: hidden;
            }

            .spec-scroll-borimg {
                border: 1px solid #E45858 !important;
                padding: 1px !important;
            }

            .jqZoomPup {
                background-image: url(img/Transparent-bg.png);
                background-repeat: no-repeat;
                background-size: cover;
                z-index: 10;
                visibility: hidden;
                position: absolute;
                top: 0px;
                left: 0px;
                width: 20px;
                height: 20px;
                border: 1px solid #aaa;
                opacity: 0.5;
                -moz-opacity: 0.5;
                -khtml-opacity: 0.5;
                filter: alpha(Opacity=50);
            }

            .spec-preview {
                width: 100%;
                border: 1px solid #E9E9E9;
            }

            .txt-gray-EAEAEA {
                color: #EAEAEA !important;
            }
        </style>
    </head>

    <body>
        <div class="w430 " style="margin:auto;">
            <!--产品参数开始-->
            <div id="preview" class="spec-preview h430">
                <span class="jqzoom">
                <img jqimg="img/b1.jpg" src="img/s1.jpg" class="w h"/></span>
                <!--默认的第一张图-->
            </div>
            <!--缩图开始-->
            <div class="spec-scroll">
                <a class="prev f28 y_pore">
                    < </a>
                        <a class="next f28 y_pore">
                            >
                        </a>
                        <div class="items">
                            <ul>
                                <li><img class="w h" bimg="img/b1.jpg" src="img/s1.jpg" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/1.png" src="img/1.png" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/b1.jpg" src="img/s1.jpg" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/b1.jpg" src="img/s1.jpg" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/b1.jpg" src="img/s1.jpg" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/1.png" src="img/1.png" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/1.png" src="img/1.png" οnmοusemοve="preview(this);"></li>
                                <li><img class="w h" bimg="img/1.png" src="img/1.png" οnmοusemοve="preview(this);"></li>
                            </ul>
                        </div>
            </div>
            <!--缩图结束-->
        </div>
    </body>

</html>
<script type="text/javascript" src="js/jquery.jqzoom.js"></script>
<script>
    function tabs(tabId, tabNum) {
        //设置点击后的切换样式
        $(tabId + " .tab li").removeClass("curr");
        $(tabId + " .tab li").eq(tabNum).addClass("curr");
        //根据参数决定显示内容
        $(tabId + " .tabcon").hide();
        $(tabId + " .tabcon").eq(tabNum).show();
    }
    //==================图片详细页函数=====================
    //鼠标经过预览图片函数
    function preview(img) {
        $("#preview .jqzoom img").attr("src", $(img).attr("src"));
        $("#preview .jqzoom img").attr("jqimg", $(img).attr("bimg"));
        $(".spec-scroll .items ul li img").removeClass("spec-scroll-borimg")
        $(img).addClass("spec-scroll-borimg")
    }
    $(function() {
        var tempLength = 0; //临时变量,当前移动的长度
        $(".spec-scroll .items ul li").eq(0).find("img").addClass("spec-scroll-borimg")
        if(tempLength <= 0) {
            $(".spec-scroll .prev").addClass("txt-gray-EAEAEA")
        }
        var viewNum = 5; //设置每次显示图片的个数量
        var moveNum = 2; //每次移动的数量
        var moveTime = 300; //移动速度,毫秒
        var scrollDiv = $(".spec-scroll .items ul"); //进行移动动画的容器
        var scrollItems = $(".spec-scroll .items ul li"); //移动容器里的集合
        var moveLength = scrollItems.eq(0).width() * moveNum; //计算每次移动的长度
        var countLength = (scrollItems.length - viewNum) * scrollItems.eq(0).width(); //计算总长度,总个数*单个长度

        $(".jqzoom").jqueryzoom({
            xzoom: 380,
            yzoom: 410
        });
        //上一张
        $(".spec-scroll .prev").bind("click", function() {
            if(tempLength > 0) {
                if(tempLength > moveLength) {
                    scrollDiv.animate({
                        left: "+=" + moveLength + "px"
                    }, moveTime);
                    tempLength -= moveLength;
                    $(".spec-scroll .next").removeClass("txt-gray-EAEAEA")
                } else {
                    scrollDiv.animate({
                        left: "+=" + tempLength + "px"
                    }, moveTime);
                    tempLength = 0;
                    $(".spec-scroll .prev").addClass("txt-gray-EAEAEA")
                }
            }
        });
        //下一张
        $(".spec-scroll .next").bind("click", function() {
            if(tempLength < countLength) {
                if((countLength - tempLength) > moveLength) {
                    scrollDiv.animate({
                        left: "-=" + moveLength + "px"
                    }, moveTime);
                    tempLength += moveLength;
                    $(".spec-scroll .prev").removeClass("txt-gray-EAEAEA")
                } else {
                    scrollDiv.animate({
                        left: "-=" + (countLength - tempLength) + "px"
                    }, moveTime);
                    tempLength += (countLength - tempLength);
                    $(".spec-scroll .next").addClass("txt-gray-EAEAEA")
                }
            }
        });

        $(".index_img_cn img").click(function() {
            var num = $(this).index()
            $(this).parent().find("img").removeClass("bo-red-D82D2Dx2")
            $(this).addClass("bo-red-D82D2Dx2")
            var img_url = $(this).attr("src");
            var this_Carousel = $(this).parents(".width-93p").find(".Carousel");
            this_Carousel.show(500);
            this_Carousel.find("img").attr("src", img_url)
            var num_max = $(this).parent().find("img").length - 1
            if(num == 0) {
                this_Carousel.find(".left").hide()
            } else {
                this_Carousel.find(".left").show()
            }
            if(num == num_max) {
                this_Carousel.find(".right").hide()
            } else {
                this_Carousel.find(".right").show()
            }
        })
        $(".Carousel .left").click(function() { //上一张图
            var img_box = $(this).parents(".width-93p").find(".index_img_cn")
            var index = 0;
            for(var i = 0; i < img_box.find("img").length; i++) {
                if(img_box.find("img").eq(i).hasClass('bo-red-D82D2Dx2')) {
                    index = i - 1;
                    $(this).parents(".width-93p").find(".index_img_cn img").removeClass("bo-red-D82D2Dx2")
                    $(this).parents(".width-93p").find(".index_img_cn img").eq(index).addClass("bo-red-D82D2Dx2")
                    var url = img_box.find("img").eq(index).attr("src")
                    $(this).parent().find("img").attr("src", url)
                    break;
                }
            }
            if(index == 0) {
                $(this).hide()
            }
            $(this).parents(".width-93p").find(".Carousel .right").show()
        })
        $(".Carousel .right").click(function() { //下一张图
            var img_box = $(this).parents(".width-93p").find(".index_img_cn")
            var index = 0;
            for(var i = 0; i < img_box.find("img").length; i++) {
                if(img_box.find("img").eq(i).hasClass('bo-red-D82D2Dx2')) {
                    index = i + 1;
                    $(this).parents(".width-93p").find(".index_img_cn img").removeClass("bo-red-D82D2Dx2")
                    $(this).parents(".width-93p").find(".index_img_cn img").eq(index).addClass("bo-red-D82D2Dx2")
                    var url = img_box.find("img").eq(index).attr("src")
                    $(this).parent().find("img").attr("src", url)
                    break;
                }
            }
            if(index == img_box.find("img").length - 1) {
                $(this).hide()
            }
            $(this).parents(".width-93p").find(".Carousel .left").show()

        })
    })
</script>

214933_Guzw_3010603.png

 

转载于:https://my.oschina.net/u/3010603/blog/1630698

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值