码迷,mamicode.com
首页 > 其他好文 > 详细

商品图片切换+放大镜

时间:2016-12-02 22:47:04      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:blog   com   over   oms   div   滚动   body   document   src   

<dl style="float:left" id="imgshow">
    <dd>
        <div class="m_c_l_movebox">
            <div>
                <div>
                    <a class="on" href="javascript:;" supsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657.jpg" bigsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657.jpg" rel="http://pic11.secooimg.com/product/500/500/76/57/10327657.jpg">
                        <img src="http://pic11.secooimg.com/product/80/80/76/57/10327657.jpg" width="80" height="80">
                        <i></i>
                    </a>
                    <a href="javascript:;" supsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_1.jpg" bigsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_1.jpg" rel="http://pic11.secooimg.com/product/500/500/76/57/10327657_1.jpg" class="imgselect">
                        <img src="http://pic11.secooimg.com/product/80/80/76/57/10327657_1.jpg" width="80" height="80">
                        <i></i>
                    </a>
                    <a href="javascript:;" supsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_2.jpg" bigsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_2.jpg" rel="http://pic11.secooimg.com/product/500/500/76/57/10327657_2.jpg" class="">
                        <img src="http://pic11.secooimg.com/product/80/80/76/57/10327657_2.jpg" width="80" height="80">
                        <i></i>
                    </a>
                    <a href="javascript:;" supsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_3.jpg" bigsrc="http://pic11.secooimg.com/product/500/500/76/57/10327657_3.jpg" rel="http://pic11.secooimg.com/product/500/500/76/57/10327657_3.jpg" class="">
                        <img src="http://pic11.secooimg.com/product/80/80/76/57/10327657_3.jpg" width="80" height="80">
                        <i></i>
                    </a>
                </div>
            </div>
        </div>
    </dd>
    <dt>
        <img class="jqzoom" src="http://pic11.secooimg.com/product/500/500/76/57/10327657.jpg" alt="http://pic11.secooimg.com/product/500/500/76/57/10327657.jpg" width="399" height="398">
        <div class="zoomspan" style="display: none; left: 0px; top: 198px;"></div>
    </dt>
</dl>

<script type="text/javascript">
    /*小图切大图*/
    $(#imgshow dd a).mouseover(function () {
        $(this).siblings().removeClass(on);
        $(this).addClass(on);
        $(#imgshow dt img).attr(src, $(this).attr(bigsrc));
        $(#imgshow dt img).attr(alt, $(this).attr(supsrc));
    });
    /*放大镜*/
    !function(a) {
        a.fn.jqueryzoom = function(b) {
            var c = {
                xzoom: 200,
                yzoom: 200,
                offset: 10,
                position: "right"
            },
            d = a(this);
            a.extend(c, b);
            var e = "";
            a(this).parent().hover(function() {
                var b = d.offset().left,
                f = d.offset().top,
                g = a(this).find("img").get(0).offsetWidth,
                h = a(this).find("img").get(0).offsetHeight,
                i = e = a(this).find("img").attr("alt");
                a(this).find("img").attr("alt", ""),
                0 == a("div.zoomdiv").size() && a(this).find("img").after("<div class=‘zoomdiv‘><img class=‘bigimg‘ src=‘" + i + "‘ width=‘height‘ height=‘160%‘/></div>"),
                0 == a("div.zoomspan").size() && a(this).find("img").eq(0).after("<div class=‘zoomspan‘></div>"),
                a("div.zoomdiv").css({
                    top: c.top,
                    left: c.left,
                }).width(c.xzoom).height(c.yzoom).show(),
                a("div.zoomspan").show(),
                a(document.body).mousemove(function(c) {
                    var d = a(".bigimg").get(0).offsetWidth,
                    e = a(".bigimg").get(0).offsetHeight,
                    i = "x",
                    j = "y";
                    if (isNaN(j) | isNaN(i)) var j = Math.round(d / g),
                    i = Math.round(e / h);
                    var k = {};
                    k.x = c.pageX,
                    k.y = c.pageY;
                    var l = k.x - b - 100,
                    m = k.y - f - 100;
                    0 > l && (l = 0),
                    l > g - 200 && (l = g - 200),
                    0 > m && (m = 0),
                    m > h - 200 && (m = h - 200),
                    a("div.zoomspan").css({
                        left: l + "px",
                        top: m + "px",
                    }),
                    scrolly = k.y - f - 1 * a("div.zoomdiv").height() / i / 2,
                    a("div.zoomdiv").scrollTop(scrolly * i),
                    scrollx = k.x - b - 1 * a("div.zoomdiv").width() / j / 2,
                    a("div.zoomdiv").scrollLeft(scrollx * j)
                })
            },
            function() {
                a(this).find("img").attr("alt", e),
                a("div.zoomdiv").hide().remove(),
                a(document.body).unbind("mousemove"),
                a(".lenszoom").remove(),
                a("div.zoomspan").hide()
            })
        }
    } (jQuery);
    //详情图片滚动,放大
    $("img.jqzoom").jqueryzoom({
         xzoom: 460,
         yzoom: $("div.info_l")[0].offsetHeight-2,
         offset: 30,
         left: 430,
         top: -1,
         position: "right"
     });
</script>

商品图片切换+放大镜

标签:blog   com   over   oms   div   滚动   body   document   src   

原文地址:http://www.cnblogs.com/ndood/p/6127199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!