Demos:

1Basic Drop down

Source:

$('#demoBasic').ddslick({
    data: ddData,
    width: 300,
    imagePosition: "left",
    selectText: "Select your favorite social network",
    onSelected: function (data) {
        console.log(data);
    }
});

Plugin requires specific JSON data format to populate dropdown options. Click here to see the sample JSON data for the plugin .

2GET Selected Dropdown Option

Source:
$('#demoShowSelected').ddslick({
    data: ddData,
    selectText: "Select your favorite social network",
});

$('#showSelectedData').on('click', function () {
    var ddData = $('#demoShowSelected').data('ddslick');
    displaySelectedData("2: Getting Selected Dropdown Data" , ddData);
});

You may use jquery .data() with your selector to get data from plugin. $('#demoShowSelected').data('ddslick'); will return a js object that contains:

3SET selected Dropdown Option

Try an index between 0 to 4

Source:
$('#demoSetSelected').ddslick({
    data: ddData,
    selectText: "Select your favorite social network"
});

$('#btnSetSelected').on('click', function () {
    var i = $('#setIndex').val();
    if(i >= 0 && i <5)
       $('#demoSetSelected').ddslick('select', {index: i });
    else 
       $('#setIndexMsg').effect('highlight',2400);
});

You may use plugin's select method like $('#demoSetSelected').ddslick('select', {index: i });
to select a particular index.

4Callback Function on Dropdown Selection

Source:
$('#demoCallback').ddslick({
    data: ddData,
    selectText: "Select your favorite social network",
    onSelected: function(data){
        displaySelectedData("3: Callback Function on Dropdown Selection" , data);
    }
});

Use plugin's onSelected callback function on selecting one of the drop down options. The callback data will include:

5Dropdown with default selection

Source:
$('#demoDefaultSelection').ddslick({
    data: ddData,
    defaultSelectedIndex:2
});

Use Zero based plugin option defaultSelectedIndex to set up plugin to pre select the index, when first initializing.
Note:When there is no selectText the plugin selects the first item index[0] from dropdown options.

6Dropdown with image on right

Source:
$('#demoImageRight').ddslick({
    data: ddData,
    imagePosition:"right",
    selectText: "Select your favorite social network"
});

You have the flexibility to position image either on left or right using imagePosition, depending on your preference.
Also you can add your own styles to these images by modifying their CSS class .dd-option-image, .dd-selected-image on your page. For e.g. plugin sets the default max-width for images to 64px, that you can overwrite by adding these classes to your page and overwriting max-width style.

7Dropdown with truncated description

Source:
$('#demoTruncated').ddslick({
    data: ddDataLongDescription,
    selectText: "Select your favorite social network",
    truncateDescription: true,
    onSelected: function(data){
        displaySelectedData("5: Dropdown with truncated description", data);
    }
});

By default plugin will truncate the description in selected view if it overflows. You may however turn the default behavior by setting truncateDescription:false to show the complete description. Either way you still get the complete description with returned selected data. Also use .dd-desc to add your own styles to description.


下载代码说明
X关闭

ddSlick 基于jQuery的下拉图像和描述插件[脚本之家首发]

ddSlick是一个免费的,轻量级的jQuery插件,允许你创建一个自定义的下拉图像和描述。插件的特点: 为下拉菜单添加图片与描述 使用json来填充下拉选项 使用最少的css并且没有加载外部样式表 支持选择事件回调函数 即使没有图片或描述也可以正常执行实例代码: [code] $('#demoBasic').ddslick({ data: ddData, width: 300, imagePo