文章插图
各位朋友大家早上好!
今天给大家带来的是 八种select下拉选择特效源码!
在日常工作中会经常遇到!
大家可以按照自己的意愿,做成喜欢的样子!
有想要文件版源码的可以私聊小编!
废话不多说,上源码!
JS:/**
* selectFx.js v1.0.0
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/
;( function( window ) {
‘use strict’;
/**
* based on from https://github.com/inuyaksa/jquery.nicescroll/blob/master/jquery.nicescroll.js
*/
function hasParent( e, p ) {
if (!e) return false;
var el = e.target||e.srcElement||e||false;
while (el && el != p) {
el = el.parentNode||false;
}
return (el!==false);
};
/**
* extend obj function
*/
function extend( a, b ) {
for( var key in b ) {
if( b.hasOwnProperty( key ) ) {
a[key] = b[key];
}
}
return a;
}
/**
* SelectFx function
*/
function SelectFx( el, options ) {
this.el = el;
this.options = extend( {}, this.options );
extend( this.options, options );
this._init();
}
/**
* SelectFx options
*/
SelectFx.prototype.options = {
// if true all the links will open in a new tab.
// if we want to be redirected when we click an option, we need to define a data-link attr on the option of the native select element
newTab : true,
// when opening the select element, the default placeholder (if any) is shown
stickyPlaceholder : true,
// callback when changing the value
onChange : function( val ) { return false; }
}
/**
* init function
* initialize and cache some vars
*/
SelectFx.prototype._init = function() {
// check if we are using a placeholder for the native select box
// we assume the placeholder is disabled and selected by default
var selectedOpt = this.el.querySelector( ‘option[selected]’ );
this.hasDefaultPlaceholder = selectedOpt && selectedOpt.disabled;
// get selected option (either the first option with attr selected or just the first option)
this.selectedOpt = selectedOpt || this.el.querySelector( ‘option’ );
// create structure
this._createSelectEl();
// all options
this.selOpts = [].slice.call( this.selEl.querySelectorAll( ‘li[data-option]’ ) );
// total options
this.selOptsCount = this.selOpts.length;
// current index
this.current = this.selOpts.indexOf( this.selEl.querySelector( ‘li.cs-selected’ ) ) || -1;
// placeholder elem
this.selPlaceholder = this.selEl.querySelector( ‘span.cs-placeholder’ );
// init events
this._initEvents();
}
/**
* creates the structure for the select element
*/
SelectFx.prototype._createSelectEl = function() {
var self = this, options = ”, createOptionHTML = function(el) {
var optclass = ”, classes = ”, link = ”;
if( el.selectedOpt && !this.foundSelected && !this.hasDefaultPlaceholder ) {
classes += ‘cs-selected ‘;
this.foundSelected = true;
}
// extra classes
if( el.getAttribute( ‘data-class’ ) ) {
classes += el.getAttribute( ‘data-class’ );
}
// link options
if( el.getAttribute( ‘data-link’ ) ) {
link = ‘data-link=’ + el.getAttribute( ‘data-link’ );
以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!
「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助:- 教你制作百分比柱形图 excel怎么画柱状图怎么标数据
- excel一键去除公式 excel删除公式保留数据公式
- 附学习路线图 java学习体系框架
- 设置按钮无边框的方法 js复选框是否选中
- 误删的excel表格恢复方法 excel工作表误删后找回老版本
- excel表格向下三角箭头 excel箭头怎么输入
- 电脑输入法不显示选字框 电脑输入法怎么删除
- excel转换成pdf文件方法 excel转pdf分页了怎么办
- 表格分列怎么用 excel分列怎么用
- 强制换行和自动换行 excel表格里换行按什么键