【问题标题】:Why is this slider script breaking when minified and combined?为什么这个滑块脚本在缩小和组合时会中断?
【发布时间】:2015-05-17 19:30:42
【问题描述】:

是时候缩小我的 js 了,我遇到了一些不想这样做的脚本:

首先我们有 owl-slider。我有几个滑块和一些其他随机的 JS,希望我能把它结合起来

$(document).ready(function() {
  $("#sliderId").owlCarousel({
   autoPlay:true,
   navigation : false,
   slideSpeed : 200,
   paginationSpeed : 400,
   items: 3,
   loop:true,
   itemsTablet: true,
   itemsMobile : true
  });
});

第二个用于显示随机文本的旧脚本:

 $(document).ready(function change() {
    "use strict";
     var messages = [
                "text 1",
                "text 2",
                     ], i = 0;
var msg = messages[Math.floor(Math.random()*messages.length)];
$('#comments').html(msg).fadeIn(600).delay(10000).fadeOut(600, change);
      })();

我怎么可能将这两个合并到一个 js 文件中运行?

【问题讨论】:

    标签: javascript jquery minify


    【解决方案1】:

    缩小器在某些情况下非常严格。所以你的 Javascript 文件中有一个小逗号错误:

     $(document).ready(function change() {
        "use strict";
         var messages = [
           "text 1",
           "text 2" // Here you have to delete the comma
         ], i = 0;
         var msg = messages[Math.floor(Math.random()*messages.length)];
         $('#comments').html(msg).fadeIn(600).delay(10000).fadeOut(600, change);
     })();
    

    解决这个问题,也许你最喜欢的 minifier 和 combiner 可以工作 ;)

    【讨论】:

      猜你喜欢
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 2019-01-09
      • 2015-09-16
      • 2015-03-11
      • 2018-05-17
      相关资源
      最近更新 更多