javascript - angularjs/javascript - 在未应用的图像上向左滚动

标签 javascript jquery html css angularjs

我有一个比它的 div 大的图像,允许用户在图像上左右滚动。我正在尝试将图像居中,以便用户看到图像的中心。我试过向左滚动

View :

<div style="overflow: scroll;" ng-controller="ColorsCtrl">

    <div ng-show="!isLandscape">
        <div  style="overflow: scroll;" ng-if="isSelected(color.code)" ng-repeat="color in colors">
            <img id="fullSwatch" ng-src="{{ images.swatches_large[color.code] }}" full-swatch>
        </div>
    </div>

</div>

我有一个指令可以操纵图片的图像以允许滚动。

colorsController.directive('fullSwatch', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('load', function() {

                var img = element[0];

                //swap width and height values because they are before orientation change
                var h = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
                var w = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

                var imageWidth = img.width;
                var imageHeight = img.height;

                var aspectRatio = imageWidth / imageHeight;

                // fill image vertically
                imageHeight = h;
                imageWidth = h * aspectRatio;

                img.style.width = imageWidth + "px";
                img.style.height = imageHeight + "px";
                img.style.maxWidth = "none";

                // add scroll left to parent container to center image
                var container = img.parentNode();

                var scrollLeft = imageWidth / 2;
                container.scrollLeft = scrollLeft;

            });
        }
    };
});

没有应用向左滚动,图像从一直向左开始。

最佳答案

尝试添加 overflow:auto;在样式标签中是这样的:
<div style="overflow:auto;"></div>
你可以看到我的源代码 quiz site寻求帮助

关于javascript - angularjs/javascript - 在未应用的图像上向左滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28789286/

相关文章:

javascript - AngularJS:有没有更好的方法来同步两个 promise ?

javascript - 浏览器后退按钮上未定义 slimScroll

html - 下拉菜单间距的联系表格 7 问题

javascript - 为什么 jquery 选择器不适用于新替换的标签?

javascript - 在图像后面对齐视频

javascript - 如果向下滚动,弹出位置会改变

javascript - 单击一个单选按钮并检测其他未选中的 radio ,在我的 jquery 情况下该怎么做?

javascript - 使用 Javascript 在 safari 中获取 NAN 形式的日期值

jquery - 如何连接非空、断开连接的节点?

javascript - 如何在按键的同时格式化输入值