js+css模仿淘宝电商网站商品评论图片点击放大缩小效果代码

代码语言:html

所属分类:图片放大

代码描述:js+css模仿淘宝电商网站商品评论图片点击放大缩小效果代码

代码标签: 电商 网站 商品 评论 图片 点击 放大 缩小 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!doctype html>
<html>
<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">
    <style>
        * {
            padding: 0;
            margin: 0;
            font-style: normal;
            font-family: 'siyuan','黑体'
        }
        dd,dl,dt,em,i,p,textarea,a,div {
            padding: 0;
            margin: 0;
        }
        a {
            text-decoration: none;
            color: #404040
        }
        img {
            border: 0;
        }
        ul,li {
            padding: 0;
            margin: 0;
            list-style: none;
        }


        .pltop {
            width: 800px;
            margin: 10px auto 0px auto;
            background: #EFEFEF;
            border: 1px #c8c8c8 solid;
            height: 24px;
            line-height: 24px;
            font-size: 14px;
            padding: 5px 10px;
        }

        .pinln {
            width: 800px;
            border-bottom: 1px #e3e3e3 solid;
            margin: 10px auto;
            display: flex;
            justify-content: space-between;
            align-items: center
        }
        .pinln .xinx {
            width: 530px;
        }
        .pinln .xinx .text {
            font-size: 14px;
            width: 100%
        }
        .pinln .xinx .time {
            font-size: 14px;
            color: #999
        }
        .pinln .fenlei,.pinln .name {
            width: 135px;
            font-size: 14px;
        }
        .pinln .fenlei span,.pinln .name span {
            color: #999
        }
        .pinln .name tt {
            display: block;
            color: #C09459
        }

        /*图片评价*/
        .tm-m-photos,.tm-m-photos-thumb {
            zoom: 1;
        }
        /*评论小图片*/
        .tm-m-photos-thumb {
            margin: 10px 0;
            list-style-type: none;
            height: 45px
        }
        .tm-m-photos-thumb li {
            float: left;
            border: 2px solid #f2f2f2;
            padding: 2px;
            margin-right: 8px;
            position: relative;
            transition: border-color .2s ease-out
        }
        .tm-m-photos-thumb .tm-current {
            border: 2px solid #f23d6a;
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -o-border-radius: 2px;
            cursor: auto
        }

        /*选中图片后下面的箭头*/
        .tm-photos-arrow {
            width: 0;
            height: 0;
            line-height: 0;
            font-size: 0;
            border: 6px dashed transparent;
            border-top: 6px solid #f23d6a;
            position: absolute;
            left: 15px;
            opacity: 0;
            bottom: -12px;
            background: 0 0
        }
        .tm-current .tm-photos-arrow {
            opacity: 1
        }
        /*缩略图大小*/
        .tm-m-photos-thumb img {
            display: block;
            width: 40px;
            height: 40px;
            cursor: url(//repo.bfw.wiki/bfwrepo/image/6104d2364d4b0.png),auto
        }

        /*缩略图放大*/
        .tm-m-photo-viewer,.tm-m-photo-viewer img,.tm-m-photos-thumb .tm-current img {
            cursor: url(//repo.bfw.wiki/bfwrepo/image/6104d251bed0b.png),auto
        }
        .tm-m-photo-viewer {
            position: relative;
            margin: 10px 0;
            width: 0;
            height: 0;
            overflow: hidden;
            display: none;
            transition: all .2s ease-in
        }
        .tm-m-photo-viewer img {
            max-width: 100%;
            max-height: 100%;
            border: 1px solid #ccc;
            padding: 2px;
        }
        .tm-m-photo-viewer-navleft,.tm-m-photo-viewer-navright {
            top: 0;
            bottom: 0;
            position: absolute;
            width: 30%;
            background: url(../images/s.gif)
        }
        .tm-m-photo-viewer-navleft {
            left: 0
        }
        .tm-m-photo-viewer-navright {
            right: 0
        }
        .tm-m-photo-viewer-navleft i,.tm-m-photo-viewer-navright i {
            top: 50%;
            margin-top: -24px;
            position: absolute;
            width: 48px;
            height: 48px;
            display: none
        }
        .tm-m-photo-viewer-navleft i {
            left: 0;
 
        }
        .tm-m-photo-viewer-navright i {
            right: 0;
         
        }
    </style>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
    <script>
        (function($) {
            $.fn.commentImg = function(options) {
                var defaults = {
                    activeClass: 'current',
                    nextButton: '.next',
                    prevButton: '.prev',
                    imgNavBox: '.photos-thumb',
                    imgViewBox: '.photo-viewer'
                };
                var opts = $.extend({}, defaults, options);

                this.each(function() {
                    var _this = $(this),
                    imgNav = _this.find(opts.imgNavBox).children(),
                    imgViewBox = _this.find(opts.imgViewBox),
                    prevBtn = _this.find(opts.prevButton),
                    nextBtn = _this.find(opts.nextButton),
                    src = '',
                    img = new Image();

                    function setViewImg(viewSrc) {
                        img.src = viewSrc;
                        img.onload = function () {
                            var imageWidth = img.width;
                            var imageHeight = img.height;
                            imgViewBox.show(0, function() {
                                $(this).css({
                                    "width": imageWidth, "height": imageHeight
                                }).find("img").attr('src', src);
                            });
                        }
                    }

                    imgNav.on("click", function() {
                        $(this).toggleClass(opts.activeClass).siblings().removeClass(opts.activeClass);
                        if ($(this).hasClass(opts.activeClass)) {
                            src = $(this).attr('data-src');
                            setViewImg(src);
                        } else {
                            imgViewBox.css({
                                "width": 0, "height": 0
                            }).hide();
                        }
                    });

                    imgViewBox.on("click",
                        function() {
                            imgNav.removeClass(opts.activeClass);
                            $(this).css({
                                "width": 0, "height": 0
                            }).hide();
                        });

                    prevBtn.hover(function () {
                        var index = imgNav.index(_this.find(opts.imgNavBox).children("." + opts.activeClass));
                        if (index < 1) {
                            $(this).css({
                                "cursor": "default"
                            }).children().hide();
                        } else {
                            $(this).css({
                                "cursor": "pointer"
                            }).children().show();
                        }
                    },
                        function () {
                            $(this).css({
                              .........完整代码请登录后点击上方下载按钮下载查看

网友评论0