Home > Web Front-end > JS Tutorial > body text

YUI's Tab switching implementation code_YUI.Ext related

WBOY
Release: 2016-05-16 18:29:49
Original
1367 people have browsed it

Tab switching should not depend on HTML structure, giving designers and front-end developers maximum flexibility. Principle: A tab object is divided into a control part (trigger) and a content part (sheet). When the trigger is triggered, the corresponding sheet is displayed.

Dashu wrote a TabControl code before. After two years of use, it is still very testable, which shows that this idea was relatively in line with actual needs. I changed it to a YUI-based version, which may look clearer. First visit the test page to see the effect. The complete javascript code is here.

Note: When changing to actual code, please put the Tab class under a certain namespace and do not expose it directly to the global space.

1: Use
The following are commonly used html structures, but are not limited to this.

Copy code The code is as follows:


  • t1

  • t2

  • t3


s1

s2

s3



The corresponding javascript code is as follows, All four initialization methods are possible.

Copy code The code is as follows:

var tab = new Tab($D. get('t').getElementsByTagName('li'), $D.get('s').getElementsByTagName('div'));//1
var tab = new Tab(['t1',' t2', 't3'],['s1','s2', 's3']);//2
var tab = new Tab(['t1','t2','t3'],[ 's1','s2','s3'],{ triggerEvent:'mouseover',slideEnabled:true});//3
var tab = new Tab();//4
tab.add( 't1', 's1');
tab.add('t2', 's2');
tab.add('t3', 's3');
tab.config['triggerEvent '] = 'mouseover';
tab.config['slideEnabled'] = true;
tab.onShow.subscribe(function(t, a){ ... });
tab.init( ; Define events.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!