0

例如,如何在以下色板函数中运行“._openclose()”?

http://tympanus.net/Tutorials/SwatchBook/index3.html

我尝试过类似的东西:

$( '#sb-container' ).swatchbook = function () {
    this._openclose()
}
4

2 回答 2

0

您可以根据行指定的项目触发事件closeIdx : 11

$(function() {
    $( '#sb-container' ).swatchbook( {
        // number of degrees that is between each item
        angleInc    : 15,
        neighbor    : 15,
        // if it should be closed by default
        initclosed  : true,
        // index of the element that when clicked, triggers the open/close function
        // by default there is no such element
        closeIdx    : 11
    } ); 

});

function test(){
    $('.sb-toggle').trigger('click');
}

HTML:

<div id="test" onclick="test();">Test</div>
于 2012-11-21T22:46:18.053 回答
0

There's lots of useful information in the documentation for this plugin on this page. The jQuery stuff is towards the bottom.

Without having used the plugin, I'm not sure how it works exactly but I can see right off that your 'this' is not a jQuery object. Try:

$( '#sb-container' ).swatchbook = function () {
    $(this)._openclose()
}); 

OR

$( '#sb-container' ).swatchbook = function () {
    _self._openclose()
});

_self is declared as the variable 'this' in the plugin:

var _self = this; 
于 2012-11-21T22:17:41.963 回答