html5 tab滑动效果,html5全屏响应式tab滑动选项卡切换特效

这是一个HTML5实现的全屏响应式Tab选项卡切换特效,支持键盘控制水平滑动。用户可以使用左右箭头键在不同的内容板块之间导航,包括Products、Questions、Events和Sponsors等部分。

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

特效描述:html5 全屏 响应式tab滑动选项卡 切换特效。html5 tab,响应式选项卡,全屏切换,html5选项卡

代码结构

1. 引入CSS

2. 引入JS

3. HTML代码

支持键盘控制的扁平风格水平滑动Tab选项卡

Products

Use your 'left' and 'right' arrow keys to navigate.
Quos vel omnis quibusdam at inventore atque assumenda dignissimos ipsa magni perferendis, minima neque saepe reprehenderit quisquam numquam voluptas quo placeat quaerat!

Questions

Use your 'left' and 'right' arrow keys to navigate.
Labore iure tempora magnam aliquid voluptatum sit placeat necessitatibus, adipisci est, ipsum doloremque. Id quia consequatur labore repellendus. Ab eligendi voluptatibus doloribus.

Events

Use your 'left' and 'right' arrow keys to navigate.
Earum porro, at odit. Dolorem velit asperiores quam obcaecati ex numquam aspernatur at et! Possimus blanditiis, distinctio est qui deleniti nisi dolorem!

Sponsors

Use your 'left' and 'right' arrow keys to navigate.
Autem alias perferendis facilis, quibusdam, ratione repellendus, voluptate officiis ipsa ullam magnam libero atque doloribus sunt est ea nisi iste porro excepturi.

Sponsors

Use your 'left' and 'right' arrow keys to navigate.
Autem alias perferendis facilis, quibusdam, ratione repellendus, voluptate officiis ipsa ullam magnam libero atque doloribus sunt est ea nisi iste porro excepturi.

var Nav = function () {

var nav = $('.nav'), burger = $('.burger'), page = $('.page'), section = $('.section'), link = nav.find('.nav__link'), navH = nav.innerHeight(), isOpen = true, hasT = false;

var toggleNav = function () {

nav.toggleClass('nav--active');

burger.toggleClass('burger--close');

shiftPage();

};

var shiftPage = function () {

if (!isOpen) {

page.css({

'transform': 'translateY(' + navH + 'px)',

'-webkit-transform': 'translateY(' + navH + 'px)'

});

isOpen = true;

} else {

page.css({

'transform': 'none',

'-webkit-transform': 'none'

});

isOpen = false;

}

};

var switchPage = function (e) {

var self = $(this);

var i = self.parents('.nav__item').index();

var s = section.eq(i);

var a = $('section.section--active');

var t = $(e.target);

if (!hasT) {

if (i == a.index()) {

return false;

}

a.addClass('section--hidden').removeClass('section--active');

s.addClass('section--active');

hasT = true;

a.on('transitionend webkitTransitionend', function () {

$(this).removeClass('section--hidden');

hasT = false;

a.off('transitionend webkitTransitionend');

});

}

return false;

};

var keyNav = function (e) {

var a = $('section.section--active');

var aNext = a.next();

var aPrev = a.prev();

var i = a.index();

if (!hasT) {

if (e.keyCode === 37) {

if (aPrev.length === 0) {

aPrev = section.last();

}

hasT = true;

aPrev.addClass('section--active');

a.addClass('section--hidden').removeClass('section--active');

a.on('transitionend webkitTransitionend', function () {

a.removeClass('section--hidden');

hasT = false;

a.off('transitionend webkitTransitionend');

});

} else if (e.keyCode === 39) {

if (aNext.length === 0) {

aNext = section.eq(0);

}

aNext.addClass('section--active');

a.addClass('section--hidden').removeClass('section--active');

hasT = true;

aNext.on('transitionend webkitTransitionend', function () {

a.removeClass('section--hidden');

hasT = false;

aNext.off('transitionend webkitTransitionend');

});

} else {

return;

}

}

};

var bindActions = function () {

burger.on('click', toggleNav);

link.on('click', switchPage);

$(document).on('ready', function () {

page.css({

'transform': 'translateY(' + navH + 'px)',

'-webkit-transform': 'translateY(' + navH + 'px)'

});

});

$('body').on('keydown', keyNav);

};

var init = function () {

bindActions();

};

return { init: init };

}();

Nav.init();

[removed] $(function() { function setCurrentSlide(ele, index) { $(".swiper1 .swiper-slide").removeClass("selected"); ele.addClass("selected"); //swiper1.initialSlide=index; } var swiper1 = new Swiper('.swiper1', { // 设置slider容器能够同时显示的slides数量(carousel模式)。 // 可以设置为number或者 'auto'则自动根据slides的宽度来设定数量。 // loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。 slidesPerView: 5.5, paginationClickable: true,//此参数设置为true时,点击分页器的指示点分页器会控制Swiper切换。 spaceBetween: 10,//slide之间的距离(单位px)。 freeMode: true,//默认为false,普通模式:slide滑动时只滑动一格,并自动贴合wrapper,设置为true则变为free模式,slide会根据惯性滑动且不会贴合。 loop: false,//是否可循环 onTab: function(swiper) { var n = swiper1.clickedIndex; } }); swiper1.slides.each(function(index, val) { var ele = $(this); ele.on("click", function() { setCurrentSlide(ele, index); swiper2.slideTo(index, 500, false); //mySwiper.initialSlide=index; }); }); var swiper2 = new Swiper('.swiper2', { //freeModeSticky 设置为true 滑动会自动贴合 direction: 'horizontal',//Slides的滑动方向,可设置水平(horizontal)或垂直(vertical)。 loop: false, // effect : 'fade',//淡入 //effect : 'cube',//方块 //effect : 'coverflow',//3D流 // effect : 'flip',//3D翻转 autoHeight: true,//自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化。 onSlideChangeEnd: function(swiper) { //回调函数,swiper从一个slide过渡到另一个slide结束时执行。 var n = swiper.activeIndex; setCurrentSlide($(".swiper1 .swiper-slide").eq(n), n); swiper1.slideTo(n, 500, false); } }); }); [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值