jqueryTAB插件写法

下面是本人写的一个小的tab切换的插件,欢迎提出意见交流讨论,不懂或不明白可与我联系

HTML代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tab切换--jQuery版</title>
<link rel="stylesheet" href="css/tab.css"/>
</head>
<body>
<!-- <button id="btn">测试</button>-->

<div class="tab">
<ul class="tabNav clearfix">
<li class="high">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>

<div class="tabView">
<div class="tatContent">
<div class=>夫人梵蒂冈地方官地方大风过<br/>后的风格广泛份</div>
<div>的方式并非个别辅导给你风格的花费更<br/>多风格的南方姑娘广泛的恢当年</div>
<div>都十分广泛单干户各方风格的花费放过<br/>你的很多烦恼更多发光</div>
<div>风格的好地方给你反对搞活豆发给你发<br/>的给你答的烦恼</div>
<div>风格和法国的那风格的能否度过难关的<br/>纷俄国纷</div>
</div>
</div>
</div>

<script src="lib/jquery-1.8.3.js"></script>
<script src="lib/jquery.tabs.1.0.js"></script>
<script src="js/usetab.js"></script>

</body>
</html>

CSS代码:

@import "reset.css";

body {
font-size: 14px;
font-family: microsoft yahei, Arial;
color: #575757;
}

.tab {
width: 355px;
border: 1px solid #ccc;
margin: 20px auto;
}

.tabNav {
border-bottom: 1px solid #ccc;
background: #eee;
padding: 3px 0 0 6px;
}
.tabNav li {
float: left;
cursor: default;
padding: 6px 30px;
}

.high {
background: #fff;
border: 1px solid #ccc;
border-bottom: none;
position: relative;
top: 1px;
}

.tabView {
height: 150px;
overflow: hidden;
position: relative;
}

.tatContent {
position: absolute;
}
.tatContent div {
width: 650px;
height: 150px;
float: left;
}

js插件写法代码:

/*
* 插件名称:tab切换
* 版本:1.0
* 功能参数:
*evt:事件名称 例如:click,mouseover等
*highLight:王超豹
*easing
*direction
*
* */

;(function($){
$.fn.extend({
tabs:function(option){
//定义默认参数
var settings={
evt:‘mouseover‘,
highLight:‘high‘,
direction:"left",
index:0,
target:‘.tatContent‘
}

var opts= $.extend({},settings,option),
evt=opts.evt,
high=opts.highLight,
easing=opts.easing,
direction=opts.direction,
index=opts.index,
target=$(opts.target),
$this=this,
targetChild=target.children();

this.eq(index).addClass(high).siblings().removeClass(high);
if(direction=="left"){
target.css("width",targetChild.length*targetChild.width());
}else if(direction=="top"){
target.css("height",targetChild.length*targetChild.height());
}

function move(){
$this.eq(index).addClass(high).siblings().removeClass(high);
//alert(this.length);
if(easing=="slide"){
if(direction=="left") {
target.animate({"left":(-index)*targetChild.width()},time);
}else if(direction=="top"){
target.animate({"top":(-index)*targetChild.height()},time);
}
}else {
targetChild.hide().eq(index).show();
}
}

return this.each(function(i,el){

$(this).on(evt,function(){
index=i;
move();
});
});
}
});

})(jQuery);

有不懂或不明白的地方可以联系我,欢迎交流讨论。

时间: 2024-08-06 23:21:14

jqueryTAB插件写法的相关文章

jquery插件写法

下面的文章是我复制粘贴的,是学习jquery插件写法时搜到的好的教程.谢谢这些人写的博客,为表示尊重,我将博客的地址也粘贴出来,希望可以帮到其他人. -----------------------------------------------------分割线--------------------------------------------------------------------------------------------------- JQuery插件写法的总结 最近Web

jQuery插件写法总结以及面向对象方式写法总结

[转自]jQuery插件写法总结以及面向对象方式写法总结:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented-manner.html

jQuery插件写法总结

jQuery插件写法总结:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented-manner.html

jQuery 插件写法2

转载:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented-manner.html 一.jQuery插件的类型 1. jQuery方法 很大一部分的jQuery插件都是这种类型,由于此类插件是将对象方法封装起来,在jQuery选择器获取jQuery对象过程中进行操作,从而发挥jQuery强大的选择器优势. 2. 全局函数法 可以把自定义的功能函数独立附加到jQ

一天一点新东西-jq插件写法

1.通过$.extend()来扩展jQuery $.extend({ test: function () { //函数方法 }}) 直接通过$调用函数$.test() 2.通过$.fn 向jQuery添加新的方法 index.js ;(function ($,window,document,undefined) {//分号是好习惯 var methods={ init: function () { return this.each(function () { //相应方法 }) }, other

(function($){….})(jQuery)一种js插件写法

我们先看第一个括号里边的内容:function($){….},这不就是一个匿名的函数吗?但是它的形参比较奇怪,是$,这里主要是为了不与其它的库冲突. 这样我们就比较容易理解第一个括号内的内容就是定义了一个匿名函数,我们在调用函数的时候,都是函数名后边加上括号以及实参,但是由于操作符的优先级我们定义的匿名函数也需要用()括起来. 现在我想大家已经很清楚这句话是什么意思了吧.第一个括号表示定义了一个匿名函数,然后第二个函数表示为该函数传递的参数,整个结合起来意思就是,定义了一个匿名函数,然后又调用该

jquery组件和插件写法

<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="智能社 - zhinengshe.com" /> <meta name="copyright" content="智能社 - zhinengshe.com" /> <t

个人tab切换jq效果插件写法

在写插件之前我们需要引用一个jquery库 html代码如下: <div class="ina_tab"> <ul><li>1</li><li>2</li><li>3</li></ul> <div class="ina_nr">11</div> <div class="ina_nr">22</div

插件写法(基于继承)

/** * @author: xiangliang.zeng * @description: * @Date: 2016/12/12 16:57 * @Last Modified by: xiangliang.zeng * @Last Modified time: 2016/12/12 16:57 */ (function(factory) { var root = (typeof self == "object" && self.self == self &&