- 在线时间
- 983 小时
- 专家
- 0
- UID
- 281860
- 注册时间
- 2006-8-7
- 帖子
- 2057
- 精华
- 1
- 积分
- 5862
- 居住地
- 浙江省 杭州市
- 离线
- 20 天
专长: 前端制作,Javascript编程,ASP
- 帖子
- 2057
- 体力
- 5637
- 威望
- 45
- 居住地
- 浙江省 杭州市
|
发表于 2009-7-17 09:19:52
|显示全部楼层
回复 177# fhrd123 的帖子
只有整了个滚动分页的效果,看看吧!!
代码调整优化了下:
- YAO.simpleTab = function(oConfigs){
- this.tabCnt = (oConfigs.tabId) ? YAO.getEl(oConfigs.tabId) : (oConfigs.tabRoot || null);
- this.tabs = (oConfigs.tTag) ? this.tabCnt.getElementsByTagName(oConfigs.tTag) : (oConfigs.tabs || null);
- this.contents = (oConfigs.cTag) ? this.tabCnt.getElementsByTagName(oConfigs.cTag) : (oConfigs.contents || null);
- this.length = this.tabs.length || 0;
- this.defaultIndex = oConfigs.defaultIndex || 0;
- this.lastIndex = this.defaultIndex;
- this.lastTab = this.tabs[this.lastIndex] || null;
- this.lastContent = this.contents[this.lastIndex] || null;
- this.evtName = oConfigs.evt || 'mouseover';
- this.defaultClass = oConfigs.defaultClass || 'current';
- this.previousClass = oConfigs.previousClass || '';
- this.hideAll = oConfigs.hideAll || false;
- this.auto = oConfigs.auto || false;
- this.autoSpeed = oConfigs.autoSpeed || 6000;
- this.fadeUp = oConfigs.fadeUp || false;
- this.scroll = oConfigs.scroll || false;
- this.scrollId = oConfigs.scrollId || null;
- this.scrollSpeed = oConfigs.scrollSpeed || 5;
- this.direction = oConfigs.direction || 'V';
- this.activeTag = oConfigs.activeTag || 'IMG';
- this.stepHeight = oConfigs.stepHeight || 0;
- this.stepWidth = oConfigs.stepWidth || 0;
- this.ajax = oConfigs.ajax || false;
- this.aPath = oConfigs.aPath || '';
-
- var i, that = this,scrollWidth,scrollHeight,activeObj=null,itemHeight=0,itemWidth=0;
- if (this.tabs && this.contents) {
- if (this.auto) {
- this.timer = setTimeout(function(){
- that.autoChange();
- }, that.autoSpeed);
- }
- if (!this.hideAll) {
- YAO.addClass(this.lastTab, this.defaultClass);
- if (!this.ajax && !this.scroll) {
- if (this.lastContent) {
- this.lastContent.style.display = 'block';
- }
- }
- if (this.ajax) {
- this.ajaxTab(this.lastTab);
- }
- if (this.scroll) {
- this.scrollCnt((this.lastContent || this.contents), this.defaultIndex);
- }
- }
- else {
- YAO.removeClass(this.lastTab, this.defaultClass);
- }
- for (i = 0; i < this.length; ++i) {
- if (i !== this.defaultIndex) {
- YAO.removeClass(this.tabs[i], 'current');
- if (!this.ajax && !this.scroll) {
- this.contents[i].style.display = 'none';
- }
- }
- YAO.on(this.tabs[i],this.evtName, function(index){
- return function(event){
- var evt = null, currentContent = (that.ajax || (that.scroll && (that.stepHeight || that.stepWidth))) ? that.contents : (that.contents[index] || null);
-
- that.setCurrent.call(that, currentContent, index);
- that.lastIndex = index;
- if (that.auto) {
- that.isPause = true;
- }
- evt = event || window.event;
- YAO.stopEvent(evt);
- }
- }(i));
- YAO.on(this.tabs[i],'mouseout', function(index){
- return function(){
- if (that.hideAll && that.evtName === 'mouseover') {
- if (that.lastTab === this) {
- YAO.removeClass(this, (YAO.hasClass(this, that.defaultClass) ? that.defaultClass : 'current'));
- }
- if (that.previousClassTab) {
- YAO.removeClass(that.previousClassTab, that.previousClass);
- }
- if (!that.scroll && !that.ajax) {
- that.contents[index].style.display = 'none';
- }
- }
- else {
- if (that.auto) {
- that.isPause = false;
- }
- }
- }
- }(i));
- }
- }
- };
- YAO.simpleTab.prototype.timer = null;
- YAO.simpleTab.prototype.isPause = false;
- YAO.simpleTab.prototype = {
- autoChange: function(){
- var that = this;
- if (!this.isPause) {
- var currentContent = null, currentTab = null;
- if (this.timer) {
- clearTimeout(this.timer);
- this.timer = null;
- }
- this.lastIndex = this.lastIndex + 1;
- if (this.lastIndex === this.length) {
- this.lastIndex = 0;
- }
- currentContent = this.ajax ? this.contents : (this.contents[this.lastIndex] || null);
- this.setCurrent(currentContent, this.lastIndex);
- this.timer = setTimeout(function(){
- that.autoChange();
- }, this.autoSpeed);
- }
- else {
- this.timer = setTimeout(function(){
- that.autoChange()
- }, this.autoSpeed);
- return false;
- }
- },
- setCurrent: function(curCnt, index){
- var activeObj = null;
- curTab = this.tabs[index];
- YAO.removeClass(this.lastTab, (YAO.hasClass(this.lastTab, this.defaultClass) ? this.defaultClass : 'current'));
- if (curTab === this.tabs[this.defaultIndex]) {
- YAO.addClass(curTab, this.defaultClass);
- }
- else {
- YAO.addClass(curTab, 'current');
- }
- if (this.previousClass) {
- if (this.previousClassTab) {
- YAO.removeClass(this.previousClassTab, this.previousClass);
- }
- if (index !== 0) {
- YAO.addClass(this.tabs[index - 1], this.previousClass);
- if ((index - 1) === this.defaultIndex) {
- YAO.removeClass(this.tabs[index - 1], this.defaultClass);
- }
- this.previousClassTab = (this.tabs[index - 1]);
- }
- }
- if (!this.scroll && !this.ajax) {
- if (this.lastContent) {
- this.lastContent.style.display = "none";
- }
- if (curCnt) {
- curCnt.style.display = "block";
- }
- }
-
- if (this.fadeUp) {
- activeObj = (curCnt.tagName.toUpperCase() === 'IMG') ? curCnt : curCnt.getElementsByTagName('img')[0];
- if (this.lastContent !== curCnt) {
- YAO.fadeUp(activeObj);
- }
- }
- else {
- if (this.scroll) {
- this.scrollCnt(curCnt, index);
- }
- }
- if (!this.ajax) {
- this.lastContent = curCnt;
- }
- else {
- if (this.ajax) {
- this.ajaxTab(curTab);
- }
- }
- this.lastTab = curTab;
- },
- scrollCnt: function(curCnt,index){
- var activeObj = null, itemHeight = 0, itemWidth = 0, scrollWidth = 0, scrollHeight = 0;
- if (this.activeTag) {
- activeObj = (curCnt.tagName.toUpperCase() === this.activeTag) ? curCnt : curCnt.getElementsByTagName(this.activeTag)[0];
- }
- if (this.direction === 'V') {
- itemHeight = activeObj ? activeObj.offsetHeight : this.stepHeight;
- scrollHeight = -(index * itemHeight);
- }
- else {
- itemWidth = activeObj ? activeObj.offsetWidth : this.stepWidth;
- scrollWidth = -(index * itemWidth);
- }
- YAO.moveElement(this.scrollId, scrollWidth, scrollHeight, this.scrollSpeed);
- },
- ajaxTab: function(curTab){
- var url = '', ajaxLink = null, cnt = this.contents, uriData = this.aPath.split('/');
- ajaxLink = (curTab.tagName.toUpperCase() === 'A') ? curTab : curTab.getElementsByTagName('a')[0];
- url = uriData[0] + '/' + ajaxLink.rel + uriData[1] + uriData[2] + ajaxLink.rel;
- YAO.ajaxRequest(url, cnt, cnt.innerHTML);
- }
- };
复制代码
之前疏忽了滚动的默认定位,而且现在你可以直接设置一行或一列的滚动距离,当然你不设置,程序跟根据你的其他设置,自行计算。
[ 本帖最后由 yaohaixiao 于 2009-7-17 09:23 编辑 ] |
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
|