【问题标题】:Can I get the list of Caman.js filters?我可以获得 Caman.js 过滤器的列表吗?
【发布时间】:2019-01-25 22:11:57
【问题描述】:

有没有办法返回库中所有内置过滤器的列表。

例如:

var caman_Default_List = [];
Caman('myCanvas', function(){

     caman_Default_List= this.getAllFilters();
});

现在我正在使用它,它工作正常:

var filters =  
[   
   "vintage", "lomo", "clarity", "sinCity", "sunrise", 
   "crossProcess", "orangePeel", "love", "grungy", "jarques", "pinhole", 
   "oldBoot", "glowingSun", "hazyDays", "herMajesty", "nostalgia", 
   "hemingway", "concentrate"
];

myList.push(filters[   some filters   ]);

Caman("#myCanvas", function(){

     this[myList[index]]().render();
});

但我想知道是否有一种方法可以获取过滤器的值而无需自定义它们。 (例如,list = [ "vintage", "lomo", ......... ])

【问题讨论】:

    标签: javascript html css filter camanjs


    【解决方案1】:

    我正在查看他们的文档,但找不到任何对您尝试获取的数据有帮助的内容。我查看了他们的代码并为您提供了以下代码。

    我不确定我会 100% 信任代码,因为属性的顺序可能会改变,但至少它可以满足您的需求。

    console.log(Object.keys(Caman.prototype).slice(75, 93))
    <script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.min.js"></script>

    【讨论】:

    • 正是我想要的。非常感谢@Andrew Lohr
    【解决方案2】:

    我使用下面的代码来实现我想要的,正如@AndrewLohr 所说:

        //Declare lists to store filter names
        var list4,list5,list6,list7 = [];
    
        //Get Caman Filters (Samples : "vintage", "clarity", ... )
        list4 = (Object.keys(Caman.prototype).slice(75, 93));
        list5 = list4.toString().toUpperCase(); //To upper Case as string value (use as Label Button Name)
    
        //Get Caman Filters (Customs : "brightness", "saturation")
        list6 = Object.keys(Caman.prototype).slice(45, 55);
        //Add some more elements in the list
        list6.push("clip", "stuckBlur", "exposure", "noise", "sharpen");
    
        list7 = list6.toString().toUpperCase(); //To upper Case as string value (use as Slider Name)
    
    
        //Print lists 
        console.log(list4);console.log(list5);console.log(list6);console.log(list7);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.min.js"></script>

    【讨论】:

      猜你喜欢
      • 2019-11-30
      • 2019-06-10
      • 1970-01-01
      • 2021-07-05
      • 2014-10-01
      • 1970-01-01
      • 2014-06-30
      • 2015-03-28
      • 2023-03-15
      相关资源
      最近更新 更多