简体   繁体   English

Javascript代码的某些部分在最新的Chrome更新中停止工作

[英]Some part of Javascript code stopped working in latest Chrome update

I bought some files through codecanyon.net and they've been working fine on all browsers. 我通过codecanyon.net购买了一些文件,它们在所有浏览器上都能正常工作。 Just recently I noticed they weren't working in Chrome. 就在最近,我注意到他们不在Chrome中工作。

The code is really big and I've tried to change some things through trial and error on the js file but was unsuccessful. 该代码确实很大,我尝试通过对js文件进行反复试验来更改某些内容,但未成功。 You can see the slider at http://miguelsart.com/scroller-test . 您可以在http://miguelsart.com/scroller-test上看到滑块。

As you can see, the captions are supposed to be hidden and once you hover they have slide up. 如您所见,字幕应该是隐藏的,一旦您将其悬停,字幕就会向上滑动。 But with Chrome, the captions appear automatically and nothing happens when you hover. 但是使用Chrome浏览器时,字幕会自动显示,并且当您将鼠标悬停时没有任何反应。

I think something is wrong in this part of the code: 我认为这部分代码有问题:

//init captions
Scroller.prototype.initCaptions = function() {
    var $captions = this._$slides.find(">p:first");
    if (this._displayCaption) {
        var padding = $captions.outerWidth() - $captions.width();
        $captions.css({width:this._slideWidth - padding, display:"inline-block"}).click(preventDefault);
        if (this._captionPos == OUTSIDE) {
            var heights = $captions.map(function() { return $(this).height(); }).get();
            var maxHeight = Math.max.apply(Math, heights);                  
            $captions.css({top:this._captionAlign == TOP ? 0 : this._slideHeight, height:maxHeight});

            this._extHeight = $captions.outerHeight();                  
            if (this._captionAlign == TOP) {
                this._extOffset = this._extHeight;
            }
            $captions.addClass("outside");
        }
        else {
            if (jQuery.browser.msie && parseInt(jQuery.browser.version) > 6 && parseInt(jQuery.browser.version) < 9) {
                $captions.addClass("ie-inside");
            }
            else {
                $captions.addClass("inside");
            }
        }                   
    }
    else {
        $captions.hide();
    }
}

I've tried messing around replacing display for opacity or for visibility but nothing worked. 我已经尝试过将显示器替换为不透明或可见性,但是没有任何效果。 Does anyone have any clue what might be wrong? 有人知道什么地方可能出问题吗?

Thanks in advance! 提前致谢!

I believe I've figured out what's wrong with the author's implementation, and you are correct, it has to do with the latest version of Chrome. 我相信我已经弄清楚了作者实现的问题,您是正确的,这与最新版本的Chrome有关。

On line 43 of jquery.wt.scroller.js 在jquery.wt.scroller.js的第43行

this._mouseoverCaption = window.Touch ? false : opts.mouseover_caption;

The author of the plugin is testing for native touch capabilities (by determining if window.Touch is defined). 该插件的作者正在测试本机触摸功能(通过确定是否定义了window.Touch )。 Chrome must've recently added native touch API capabilities in a recent version. Chrome浏览器最近必须在最新版本中添加了本机touch API功能。

So what the author was going for, was saying that 'you can't hover on a touch device, so we can't show the captions on hover on a touch device so we'll just always show them' - which is logically. 所以作者要说的是:“您不能在触摸设备上悬停,因此我们无法在触摸设备上显示悬停字幕,因此我们将始终显示它们”-从逻辑上讲。

However, just because touch capabilities exist, however, doesn't mean that touch input is the default (as in this case). 但是,仅因为存在触摸功能,并不意味着默认为触摸输入(在这种情况下)。 Modernizr solves this issue (for now) by performing the following conditional: Modernizr通过执行以下条件来解决此问题(目前):

if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {

Something tells me this will also soon be broken. 有人告诉我这也很快会被打破。 ( https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js#L42 ) https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js#L42

So, long story short (too late, I know) add this to the plugin code: 因此,长话短说(我知道为时已晚)将其添加到插件代码中:

Add this to line 7 (push all lines down one): 将其添加到第7行(将所有行向下推):

var TOUCH = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch;

Find and replace all occurrences of window.Touch with TOUCH in the plugin code. 查找并替换所有出现的window.Touch ,在插件代码中TOUCH

Tell the author of the plugin I'll send him a bill. 告诉插件的作者,我会给他一张账单。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM