html5搜索框在最右侧,html5搜索框特效点击搜索框弹出分类搜索框代码

这是一个关于HTML5搜索框的特效,当用户点击搜索框时,会弹出一个分类搜索框。文章提供了实现这个效果的代码结构,包括引入CSS、JS和HTML代码部分。此外,还提到了键盘导航事件和防止表单提交的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

特效描述:html5搜索框特效 点击搜索框弹出 分类搜索框。点击搜索框弹出分类搜索框代码

代码结构

1. 引入CSS

2. 引入JS

3. HTML代码

Search

People

ResponsiveSVGs

Sara Soueidan

FreebieHalcyonDays

Rachel Smith

OffCanvas

Peter Finlan

HoverEffectsIdeasNew

Patrick Cox

DraggableDualViewSlideshow

Tim Holman

PagePreloadingEffect

Shaun Dona

Popular

PagePreloadingEffect

Page Preloading Effect

ArrowNavigationStyles

Arrow Navigation Styles

HoverEffectsIdeasNew

Ideas for Subtle Hover Effects

FreebieHalcyonDays

Halcyon Days Template

ArticleIntroEffects

Inspiration for Article Intro Effects

DraggableDualViewSlideshow

Draggable Dual-View Slideshow

Recent

TooltipStylesInspiration

Tooltip Styles Inspiration

AnimatedHeaderBackgrounds

Animated Background Headers

OffCanvas

Off-Canvas Menu Effects

TabStyles

Tab Styles Inspiration

ResponsiveSVGs

Make SVGs Responsive with CSS

NotificationStyles

Notification Styles Inspiration

(function() {

var morphSearch = document.getElementById( 'morphsearch' ),

input = morphSearch.querySelector( 'input.morphsearch-input' ),

ctrlClose = morphSearch.querySelector( 'span.morphsearch-close' ),

isOpen = isAnimating = false,

// show/hide search area

toggleSearch = function(evt) {

// return if open and the input gets focused

if( evt.type.toLowerCase() === 'focus' && isOpen ) return false;

var offsets = morphsearch.getBoundingClientRect();

if( isOpen ) {

classie.remove( morphSearch, 'open' );

// trick to hide input text once the search overlay closes

// todo: hardcoded times, should be done after transition ends

if( input.value !== '' ) {

setTimeout(function() {

classie.add( morphSearch, 'hideInput' );

setTimeout(function() {

classie.remove( morphSearch, 'hideInput' );

input.value = '';

}, 300 );

}, 500);

}

input.blur();

}

else {

classie.add( morphSearch, 'open' );

}

isOpen = !isOpen;

};

// events

input.addEventListener( 'focus', toggleSearch );

ctrlClose.addEventListener( 'click', toggleSearch );

// esc key closes search overlay

// keyboard navigation events

document.addEventListener( 'keydown', function( ev ) {

var keyCode = ev.keyCode || ev.which;

if( keyCode === 27 && isOpen ) {

toggleSearch(ev);

}

} );

/***** for demo purposes only: don't allow to submit the form *****/

morphSearch.querySelector( 'button[type="submit"]' ).addEventListener( 'click', function(ev) { ev.preventDefault(); } );

})();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值