jQuery实现有幻灯效果tab滑动切换菜单

这次给大家带来jQuery实现有幻灯效果tab滑动切换菜单,jQuery实现有幻灯效果tab滑动切换菜单的注意事项有哪些,下面就是实战案例,一起来看一下。

这是一款很不错的TAB滑动切换效果,jQuery带幻灯的tab滑动切换风格菜单导航条,点击上方的文字,下边就向左或向右滑动切换,动画效果的TAB选项卡。

运行效果截图如下:

jQuery实现有幻灯效果tab滑动切换菜单

在线演示地址如下:

http://demo.jb51.net/js/2015/jquery-flash-style-tab-cha-menu-codes/

具体代码如下:

  1. ;(function( $ ){ var $scrollTo = $.scrollTo = function( target, duration, settings ){ $(window).scrollTo( target, duration, settings ); }; $scrollTo.defaults = { axis:'xy', duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1 }; $scrollTo.window = function( scope ){ return $(window)._scrollable(); }; $.fn._scrollable = function(){ return this.map(function(){ var elem = this, isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1; if( !isWin ) return elem; var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem; return $.browser.safari || doc.compatMode == 'BackCompat' ? doc.body : doc.documentElement; }); }; $.fn.scrollTo = function( target, duration, settings ){ if( typeof duration == 'object' ){ settings = duration; duration = 0; } if( typeof settings == 'function' ) settings = { onAfter:settings }; if( target == 'max' ) target = 9e9; settings = $.extend( {}, $scrollTo.defaults, settings ); duration = duration || settings.speed || settings.duration; settings.queue = settings.queue && settings.axis.length > 1; if( settings.queue ) duration /= 2; settings.offset = both( settings.offset ); settings.over = both( settings.over ); return this._scrollable().each(function(){ var elem = this, $elem = $(elem), targ = target, toff, attr = {}, win = $elem.is('html,body'); switch( typeof targ ){ // A number will pass the regex case 'number': case 'string': if( /^([+-]=)?d+(.d+)?(px|%)?$/.test(targ) ){ targ = both( targ ); // We are done break; } // Relative selector, no break! targ = $(targ,this); case 'object': // DOMElement / jQuery if( targ.is || targ.style ) // Get the real position of the target toff = (targ = $(targ)).offset(); } $.each( settings.axis.split(''), function( i, axis ){ var Pos = axis == 'x' ? 'Left' : 'Top', pos = Pos.toLowerCase(), key = 'scroll' + Pos, old = elem[key], max = $scrollTo.max(elem, axis); if( toff ){// jQuery / DOMElement attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] ); // If it's a dom element, reduce the margin if( settings.margin ){ attr[key] -= parseInt(targ.css('margin'+Pos)) || 0; attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0; } attr[key] += settings.offset[pos] || 0; if( settings.over[pos] ) // Scroll to a fraction of its width/height attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos]; }else{ var val = targ[pos]; // Handle percentage values attr[key] = val.slice && val.slice(-1) == '%' ? parseFloat(val) / 100 * max : val; } // Number or 'number' if( /^d+$/.test(attr[key]) ) // Check the limits attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max ); // Queueing axes if( !i && settings.queue ){ // Don't waste time animating, if there's no need. if( old != attr[key] ) // Intermediate animation animate( settings.onAfterFirst ); // Don't animate this axis again in the next iteration. delete attr[key]; } }); animate( settings.onAfter ); function animate( callback ){ $elem.animate( attr, duration, settings.easing, callback && function(){ callback.call(this, target, settings); }); }; }).end(); }; $scrollTo.max = function( elem, axis ){ var Dim = axis == 'x' ? 'Width' : 'Height', scroll = 'scroll'+Dim; if( !$(elem).is('html,body') ) return elem[scroll] - $(elem)[Dim.toLowerCase()](); var size = 'client' + Dim, html = elem.ownerDocument.documentElement, body = elem.ownerDocument.body; return Math.max( html[scroll], body[scroll] ) - Math.min( html[size] , body[size] ); }; function both( val ){ return typeof val == 'object' ? val : { top:val, left:val }; };})( jQuery );$(document).ready(function() { $('#mask').css({'height':$('#panel-1').height()}); $('#panel').width(parseInt($('#mask').width() * $('#panel p').length)); $('#panel p').width($('#mask').width()); $('a[rel=panel]').click(function () { var panelheight = $($(this).attr('href')).height(); $('a[rel=panel]').removeClass('selected'); $(this).addClass('selected'); $('#mask').animate({'height':panelheight},{queue:false, duration:500}); $('#mask').scrollTo($(this).attr('href'), 800); return false; });});body { padding:0; margin:0 20px; background:#d2e0e5; font:12px arial;}#scroller-header a { text-decoration:none; color:#867863; padding:0 2px;}#scroller-header a:hover { text-decoration:none; color:#4b412f}a.selected { text-decoration:underline !important; color:#4b412f !important;}#scroller-header { background:url(images/header.gif) no-repeat; width:277px; height:24px; padding:35px 0 0 15px; font-weight:700;}#scroller-body { background:url(images/body.gif) no-repeat bottom center; width:277px; padding-bottom:30px;}#mask { width:250px; overflow:hidden; margin:0 auto;}#panel {}#panel p {float:left;}#panel ul {list-style:none;margin:0 5px;padding:0;}#panel ul li {padding:5px;color:#557482;border-bottom:1px dotted #ccc;}#panel ul li.last {border-bottom:none !important;}#panel-1 {}#panel-2 {}#panel-3 {}

    jQuery Sidebar Sliding Tab Menu Tutorial

    流行时尚网络注释历史记录网络收藏

  • Simple JQuery Image Slide Show with Semi-Transparent Caption
  • A Really Simple jQuery Plugin Tutorial
  • Create a Simple CSS + Javascript Tooltip with jQuery
  • Simple jQuery Modal Window Tutorial

  • 30 Javascript Menu Plugins and Scripts
  • 10+ jQuery photo gallery and slider plugins

  • CSS and Web Gallery List
  • Examples for Inpiration

  • 脚本之家
  • seo
  • wordpress

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

jQuery对表格标题排序

tablesorter插件使用详解(附案例)

以上就是jQuery实现有幻灯效果tab滑动切换菜单的详细内容,更多请关注【创想鸟】其它相关文章!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    编程技术

    jQuery实现省份城市滑动切换(附代码)

    2025-3-8 11:39:39

    编程技术

    jQuery实现某门户网站导航页图片拖动排序

    2025-3-8 11:39:45

    0 条回复 A文章作者 M管理员
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索