云变焦问题。缩放框不跟随光标并且不会跨越图像

时间:2018-01-16 20:42:17

标签: javascript jquery html css nopcommerce

以下是该网站的链接,以便您可以直观显示我在标题中表达的错误:

https://glassesled.com/aubrey

如果将鼠标悬停在图片上,则缩放框不会跟随光标,当您转到图像的下半部分时,缩放框会到达墙壁。以下是相关文件(我认为相关的文件)

CloudZoom.min.js文件

//////////////////////////////////////////////////////////////////////////////////
// Cloud Zoom V1.0.2
// (c) 2010 by R Cecco. <http://www.professorcloud.com>
// MIT License
//
// Please retain this copyright header in all versions of the software
//////////////////////////////////////////////////////////////////////////////////
! function($) {
    function format(t) {
        for (var o = 1; o < arguments.length; o++) t = t.replace("%" + (o - 1), arguments[o]);
        return t
    }

    function CloudZoom(t, o) {
        var e, i, s, a, n, r, l, d, u = $("img", t),
            p = null,
            c = null,
            h = null,
            m = null,
            f = null,
            g = null,
            v = 0,
            x = 0,
            b = 0,
            y = 0,
            z = 0,
            w = 0,
            O = this;
        setTimeout(function() {
            if (null === c) {
                var o = t.width();
                t.parent().append(format('<div style="width:%0px;position:absolute;top:75%;left:%1px;text-align:center" class="cloud-zoom-loading" >Loading...</div>', o / 3, o / 2 - o / 6)).find(":last").css("opacity", .5)
            }
        }, 200);
        var k = function() {
            null !== g && (g.remove(), g = null)
        };
        this.removeBits = function() {
            h && (h.remove(), h = null), m && (m.remove(), m = null), f && (f.remove(), f = null), k(), $(".cloud-zoom-loading", t.parent()).remove()
        }, this.destroy = function() {
            t.data("zoom", null), c && (c.unbind(), c.remove(), c = null), p && (p.remove(), p = null), this.removeBits()
        }, this.fadedOut = function() {
            p && (p.remove(), p = null), this.removeBits()
        }, this.controlLoop = function() {
            if (h) {
                var t = r - u.offset().left - .5 * a >> 0,
                    e = l - u.offset().top - .5 * n >> 0;
                0 > t ? t = 0 : t > u.outerWidth() - a && (t = u.outerWidth() - a), 0 > e ? e = 0 : e > u.outerHeight() - n && (e = u.outerHeight() - n), h.css({
                    left: t,
                    top: e
                }), h.css("background-position", -t + "px " + -e + "px"), x = t / u.outerWidth() * s.width >> 0, b = e / u.outerHeight() * s.height >> 0, z += (x - z) / o.smoothMove, y += (b - y) / o.smoothMove, p.css("background-position", -(z >> 0) + "px " + (-(y >> 0) + "px"))
            }
            v = setTimeout(function() {
                O.controlLoop()
            }, 30)
        }, this.init2 = function(t, o) {
            w++, 1 === o && (s = t), 2 === w && this.init()
        }, this.init = function() {
            $(".cloud-zoom-loading", t.parent()).remove();
            var e = $(".mousetrap");
            e && e.remove(), c = $.browser.msie ? t.parent().append(format("<div class='mousetrap' style='background-image:url(\"/Plugins/SevenSpikes.Nop.Plugins.CloudZoom/Scripts/cloud-zoom.1.0.2/DummyPageForIE.htm\");z-index:999;position:absolute;width:%0px;height:%1px;left:%2px;top:%3px;'></div>", u.outerWidth(), u.outerHeight(), 0, 0)).find(":last") : t.parent().append(format("<div class='mousetrap' style='z-index:999;position:absolute;width:%0px;height:%1px;left:%2px;top:%3px;'></div>", u.outerWidth(), u.outerHeight(), 0, 0)).find(":last"), c.bind("mousemove", this, function(t) {
                r = t.pageX, l = t.pageY
            }), c.bind("mouseleave", this, function(t) {
                return clearTimeout(v), h && h.fadeOut(299), m && m.fadeOut(299), f && f.fadeOut(299), p.fadeOut(300, function() {
                    O.fadedOut()
                }), !1
            }), c.bind("mouseenter", this, function(e) {
                r = e.pageX, l = e.pageY, d = e.data, p && (p.stop(!0, !1), p.remove());
                var i = o.adjustX,
                    v = o.adjustY,
                    x = u.outerWidth(),
                    b = u.outerHeight(),
                    y = o.zoomWidth,
                    z = o.zoomHeight;
                "auto" == o.zoomWidth && (y = x), "auto" == o.zoomHeight && (z = b);
                var w = t.parent();
                switch (o.position) {
                    case "top":
                        v -= z;
                        break;
                    case "right":
                        i += x;
                        break;
                    case "bottom":
                        v += b;
                        break;
                    case "left":
                        i -= y;
                        break;
                    case "inside":
                        y = x, z = b;
                        break;
                    default:
                        w = $("#" + o.position), w.length ? (y = o.zoomWidth, z = o.zoomHeight) : (w = t, i += x, v += b)
                }
                p = w.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:%2px;height:%3px;background-image:url(\'%4\');z-index:99;"></div>', i, v, y, z, s.src)).find(":last"), u.attr("title") && o.showTitle && p.append(format('<div class="cloud-zoom-title">%0</div>', u.attr("title"))).find(":last").css("opacity", o.titleOpacity), $.browser.msie && $.browser.version < 7 && (g = $('<iframe frameborder="0" src="#"></iframe>').css({
                    position: "absolute",
                    left: i,
                    top: v,
                    zIndex: 99,
                    width: y,
                    height: z
                }).insertBefore(p)), p.fadeIn(500), h && (h.remove(), h = null), a = u.outerWidth() / s.width * p.width(), n = u.outerHeight() / s.height * p.height(), h = t.append(format("<div class = 'cloud-zoom-lens' style='display:none;z-index:98;position:absolute;width:%0px;height:%1px;'></div>", a, n)).find(":last"), c.css("cursor", h.css("cursor"));
                var O = !1;
                o.tint && (h.css("background", 'url("' + u.attr("src") + '")'), m = t.append(format('<div class="cloud-zoom-tint" style="display:none;position:absolute; left:0px; top:0px; width:%0px; height:%1px; background-color:%2;" />', u.outerWidth(), u.outerHeight(), o.tint)).find(":last"), m.css("opacity", o.tintOpacity), O = !0, m.fadeIn(500)), o.softFocus && (h.css("background", 'url("' + u.attr("src") + '")'), f = t.append(format('<div class="cloud-zoom-softfocus" style="position:absolute;display:none;top:2px; left:2px; width:%0px; height:%1px;" />', u.outerWidth() - 2, u.outerHeight() - 2, o.tint)).find(":last"), f.css("background", 'url("' + u.attr("src") + '")'), f.css("opacity", .5), O = !0, f.fadeIn(500)), O || h.css("opacity", o.lensOpacity), "inside" !== o.position && h.fadeIn(500), d.controlLoop()
            })
        }, e = new Image, $(e).load(function() {
            O.init2(this, 0)
        }), e.src = u.attr("src"), i = new Image, $(i).load(function() {
            O.init2(this, 1)
        }), i.src = t.attr("href")
    }
    $(document).ready(function() {
        $(".cloud-zoom, .cloud-zoom-gallery").CloudZoom()
    }), $.fn.CloudZoom = function(options) {
        try {
            document.execCommand("BackgroundImageCache", !1, !0)
        } catch (e) {}
        return this.each(function() {
            var relOpts, opts;
            eval("var   a = {" + $(this).attr("rel") + "}"), relOpts = a, $(this).is(".cloud-zoom") ? ($(this).css({
                position: "relative",
                display: "block"
            }), $("img", $(this)).css({
                display: "block"
            }), "wrap" != $(this).parent().attr("id") && $(this).wrap('<div id="wrap" style="top:0px;position:relative;"></div>'), opts = $.extend({}, $.fn.CloudZoom.defaults, options), opts = $.extend({}, opts, relOpts), $(this).data("zoom", new CloudZoom($(this), opts))) : $(this).is(".cloud-zoom-gallery") && (opts = $.extend({}, relOpts, options), $(this).data("relOpts", opts), $(this).bind("click", $(this), function(t) {
                var o = t.data.data("relOpts");
                return $("#" + o.useZoom).data("zoom").destroy(), $("#" + o.useZoom).attr("href", t.data.attr("href")), $("#" + o.useZoom).attr("rel", t.data.attr("rel")), $("#" + o.useZoom + " img").attr("title", t.data.attr("title")), $("#" + o.useZoom + " img").attr("src", t.data.data("relOpts").smallImage), $("#" + t.data.data("relOpts").useZoom).CloudZoom(), !1
            }))
        }), this
    }, $.fn.CloudZoom.defaults = {
        zoomWidth: "auto",
        zoomHeight: "auto",
        position: "right",
        tint: !1,
        tintOpacity: .5,
        lensOpacity: .5,
        softFocus: !1,
        smoothMove: 3,
        showTitle: !0,
        titleOpacity: .5,
        adjustX: 0,
        adjustY: 0
    }
}(jQuery);

cshtml中使用的CSS文件

/*
* Copyright 2014 Seven Spikes Ltd. All rights reserved. (http://www.nop-templates.com)
* http://www.nop-templates.com/t/licensinginfo
*/

@media all and (max-width: 1000px) {

#sevenspikes-cloud-zoom:before {
    display: none;
}
#sevenspikes-cloud-zoom img {
    position: static;
}

}

@media all and (min-width: 1001px) {

/* theme overwritting styles */

.gallery {
    font-size: 0;
}
.gallery .picture-wrapper {
    /*** !!! set line-height to the appropriate height  !!! ***/
    line-height: 320px;
}
.gallery .picture-wrapper .picture:before {
    display: none;
}

/* main picture styles */

#sevenspikes-cloud-zoom {
    margin: 0;
    overflow: visible;
    text-align: center;
    font-size: 0;
}
#sevenspikes-cloud-zoom:before {
    display: none;
}
#wrap {
    display: block;
    max-width: 100%;
    vertical-align: middle;
    line-height: 0;
}
#wrap a {
    position: relative;
    max-width: 100%;
    vertical-align: middle;
    line-height: 0;
    overflow: hidden;
}
#wrap a:before {
    content: "";
    display: block;
    padding-top: 125%;
}
#wrap img {
}

/* This is the overlay element. */

#wrap > .mousetrap {
    right: 0;
    bottom: 0;
    margin: auto;
}
.cloud-zoom-lens {
    margin: 0;
    border: none;
    background-color: #fff;
    cursor: crosshair;
}

/* This is the zoom window. */

#cloudZoomWindowElement {
    left: 0;
    top: 0;
    z-index: 1;
}
#cloud-zoom-big {
    border: none;
    overflow: hidden;
    bottom: 0;
    margin: auto;
}
.overview #cloud-zoom-big {
    position: static !important; /* fix for the zoom window so that its wrapper takes the dimensions */
}

/* This is for the title text. */

.cloud-zoom-title {
    background-color: #000;
    padding: 5px;
    text-align: center;
    font-size: 11px;
    line-height: normal;
    font-weight: bold;
    color: #fff;
}

/* This is the loading message. */

.cloud-zoom-loading {
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    font-size: 0;
    background: rgba(255,255,255,.5);
    opacity: 1 !important;
}
@keyframes spinner {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}
.cloud-zoom-loading:after,
.cloud-zoom-loading:before {
    content: '';
    position: absolute;
    border: 2px solid #454545;
    width: 30px;
    height: 30px;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    outline: 1px solid transparent; /*firefox fix*/
}
.cloud-zoom-loading:after {
    animation: spinner 2.5s linear infinite;
}
.cloud-zoom-loading:before {
    width: 44px;
    height: 44px;
    animation: spinner 2.5s linear infinite;
    animation-direction: reverse;
}

/* with product ribbons enabled */

.gallery .ribbon-wrapper {
    /*never display as inline or inline-block*/
    vertical-align: middle;
    line-height: 0;
}
.gallery .ribbon-wrapper:hover .ribbon-position {
    opacity: 0;
}

}

CSHTML文件

@** Copyright 2016 Seven Spikes Ltd. All rights reserved. (http://www.nop-templates.com)
    * http://www.nop-templates.com/t/licensinginfo
*@

@using Nop.Core
@using Nop.Core.Infrastructure
@using SevenSpikes.Nop.Plugins.CloudZoom.Models

@model CloudZoomModel

@if (!string.IsNullOrEmpty(Model.DefaultPicture.FullSizeImageUrl))
{
    Html.AddCssFileParts("~/Plugins/SevenSpikes.Nop.Plugins.CloudZoom/Themes/" + Model.Theme + "/Content/cloud-zoom.1.0.2/CloudZoom.css");

    var supportRtl = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Rtl;
    if (supportRtl)
    {
        Html.AddCssFileParts("~/Plugins/SevenSpikes.Nop.Plugins.CloudZoom/Styles/CloudZoom.common.rtl.css");
    }

    Html.AddScriptParts("~/Plugins/SevenSpikes.Core/Scripts/SevenSpikesExtensions.min.js");
    Html.AddScriptParts("~/Plugins/SevenSpikes.Nop.Plugins.CloudZoom/Scripts/cloud-zoom.1.0.2/cloud-zoom.1.0.2.min.js");

    if (Model.IsIntegratedByWidget)
    {
        Html.AddScriptParts("~/Plugins/SevenSpikes.Nop.Plugins.CloudZoom/Scripts/CloudZoom.min.js");
    }

    if (Model.EnableClickToZoom)
    {
        Html.AddCssFileParts("~/Content/magnific-popup/magnific-popup.css");
        Html.AddScriptParts("~/Scripts/jquery.magnific-popup.min.js");

        <script type="text/javascript">
            $(document).ready(function () {
                $(".picture").on("click", ".mousetrap", function () {
                    var mainPictureHref = $('.picture a.cloud-zoom').attr('href');
                    var cloudZoomThumbs = $('.picture-thumbs a.cloud-zoom-gallery');
                    var imgSources = new Array();
                    var imgItem = function(source) {
                        this.src = source;
                    };

                    cloudZoomThumbs.each(function(){
                        imgSources.push(new imgItem($(this).attr('href')));
                    });

                    if(imgSources.length === 0){
                        imgSources.push(new imgItem(mainPictureHref));
                    }

                    $.magnificPopup.open({
                        items: imgSources,
                        type: 'image',
                        removalDelay: 300,
                        gallery: {
                            enabled: true
                        }
                    }, cloudZoomThumbs.filter('.active').index());
                });
            });
        </script>
    }
    <script type="text/javascript">
         @{
            string pictureAdjustmentTableName = string.Format("productAttributeValueAdjustmentTable_{0}", Model.ProductId);
            string pictureAdjustmentFuncName = string.Format("adjustProductAttributeValuePicture_CloudZoom_{0}", Model.ProductId);
            string pictureFullSizePrefix = "fullsize";
        }

        function @(pictureAdjustmentFuncName)(controlId) {
            var ctrl = $('#' + controlId);
            var pictureFullSizeUrl = '';
            if((ctrl.is(':radio') && ctrl.is(':checked')) || (ctrl.is(':checkbox') && ctrl.is(':checked'))) {
                pictureFullSizeUrl = @(pictureAdjustmentTableName)[controlId + '_@(pictureFullSizePrefix)'];
            } else if(ctrl.is('select')) {
                var idx = $('#' + controlId + " option").index($('#' + controlId + " option:selected"));
                if(idx !== -1) {
                    pictureFullSizeUrl = @(pictureAdjustmentTableName)[controlId + '_@(pictureFullSizePrefix)'][idx];
                }
            }

            if (typeof pictureFullSizeUrl == 'string' && pictureFullSizeUrl !== '') {
                var zoomGallerySelector = ".cloud-zoom-gallery[href='" + pictureFullSizeUrl + "']";
                $(zoomGallerySelector).click();

                $.event.trigger({
                    type: 'nopMainProductImageChanged',
                    target: ctrl,
                    pictureDefaultSizeUrl: pictureFullSizeUrl,
                    pictureFullSizeUrl: pictureFullSizeUrl
                });
            }
        }

        $(document).ready(function () {
            $("[id^='product_attribute_']").on('change', function() {
                @(pictureAdjustmentFuncName)($(this).attr('id'));
            });
        });
    </script>

    <div class="gallery sevenspikes-cloudzoom-gallery">
        <div class="picture-wrapper">
            <div class="picture" id="sevenspikes-cloud-zoom" data-zoomwindowelementid="@Model.ElementId"
                 data-selectoroftheparentelementofthecloudzoomwindow="@Model.SettingsModel.SelectorOfTheParentElementOfTheCloudZoomWindow"
                 data-defaultimagecontainerselector="@Model.SettingsModel.DefaultImageContainerSelector">

                <a href="@Model.DefaultPicture.FullSizeImageUrl" class="cloud-zoom" id="zoom1" rel="@Model.DefaultPicture.DefaultRelation">
                    <img src="@Model.DefaultPicture.SmallImageUrl" alt="@Model.DefaultPicture.AlternateText" title="@Model.DefaultPicture.Title" id="cloudZoomImage" itemprop="image" />
                </a>

                @if (Model.Pictures.Count > 1)
                {
                    <div class="picture-thumbs-navigation-arrow picture-thumbs-prev-arrow">
                        <span>@T("SevenSpikes.Themes.Uptown.Product.ImageThumbs.Prev")</span>
                        <img src="@Model.DefaultPicture.TinyImageUrl" data-fullSizeImageUrl="@Model.DefaultPicture.FullSizeImageUrl" alt="Previous" />
                    </div>
                    <div class="picture-thumbs-navigation-arrow picture-thumbs-next-arrow">
                        <span>@T("SevenSpikes.Themes.Uptown.Product.ImageThumbs.Next")</span>
                        <img src="@Model.DefaultPicture.TinyImageUrl" data-fullSizeImageUrl="@Model.DefaultPicture.FullSizeImageUrl" alt="Next" />
                    </div>
                    <div class="picture-thumbs">
                        @foreach (var picture in Model.Pictures)
                        {
                            <a class="cloud-zoom-gallery" href="@picture.FullSizeImageUrl" title="@picture.Title" rel="@picture.GalleryRelation">
                                <img class="cloud-zoom-gallery-img" src="@picture.TinyImageUrl" alt="@picture.AlternateText" title="@picture.Title" />
                            </a>
                        }
                    </div>
                }
            </div>
        </div>
    </div>
}

有什么想法吗?解决此问题需要更多文件? LMK!

0 个答案:

没有答案