HBuilder底部选项卡的子页面切换效果

                                     

 

 

 

1:新建sub1.htmlsub2.htmlsub3.html、sub4.htm、 sub5.html  (分别代表  ”主页“,”通讯录“........)

2:接下来,设置切换样式,新建一个js在index.html里面

 

 

 

<script type="text/javascript">

var subpages=['sub1.html','sub2.html','sub3.html','sub4.html','sub5.html '];  //以数组方式设置页面id

var subpageStyle={              //设置主页面打开的样式(设置顶部和底部,留空间给中间部分显示出来,放sub1.html这些页面)

   top:'44px',            //标题栏的高度,更多详细参数查看http://dev.dcloud.net.cn/mui/ui/#mask

   bottom:'50px'        //底部选项卡的高度

};

mui.plusReady(function(){

   var self=plus.webview.currentWebview();   //创建子窗体

   for(vari=0;i<subpages.length;i++){

      var sub=plus.webview.create(subpages[i],subpages[i],subpageStyle); //当前WebviewURL地址、ID、样式。功能:创建子窗体

      sub.hide();        //功能:隐藏页面

      self.append(sub);      //功能: 追加子页面,首个选项卡页面显示,其它均隐藏

   }

  

   plus.webview.show(subpages[0]);  //设置主页的sub.html默认显示出来,其他sub2.html默认隐藏

})

 

 mui(".mui-bar-tab").on("tap","a",function(e){ //通过.mui-bar-tap里的a元素绑定tap事件,达到批量绑定的效果

   var tagPage=this.getAttribute("href");//getAttribute()获取属性函数

   plus.webview.show(tagPage,"fade-in",100)  //fade-in淡入,100毫秒

 })

 

 

</script>

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是HBuilderX选项卡的基本代码示例: ```html <!DOCTYPE html> <html> <head> <title>HBuilderX选项卡示例</title> <style> /* 隐藏所有选项卡内容 */ .tab-content { display: none; } /* 显示当前选项卡内容 */ .tab-content.active { display: block; } /* 选项卡标题样式 */ .tab-title { display: inline-block; padding: 10px 20px; background-color: #eee; border: 1px solid #ccc; border-bottom: none; cursor: pointer; } /* 当前选项卡标题样式 */ .tab-title.active { background-color: #fff; border-bottom: 1px solid #fff; } </style> </head> <body> <div class="tab-container"> <div class="tab-title active" data-tab="tab1">选项卡1</div> <div class="tab-title" data-tab="tab2">选项卡2</div> <div class="tab-title" data-tab="tab3">选项卡3</div> <div class="tab-content active" data-tab="tab1"> <p>这是选项卡1的内容。</p> </div> <div class="tab-content" data-tab="tab2"> <p>这是选项卡2的内容。</p> </div> <div class="tab-content" data-tab="tab3"> <p>这是选项卡3的内容。</p> </div> </div> <script> // 获取选项卡标题和内容元素 const tabTitles = document.querySelectorAll('.tab-title'); const tabContents = document.querySelectorAll('.tab-content'); // 给每个选项卡标题添加点击事件 tabTitles.forEach(title => { title.addEventListener('click', () => { // 隐藏所有选项卡内容 tabContents.forEach(content => { content.classList.remove('active'); }); // 显示当前选项卡内容 const tab = title.getAttribute('data-tab'); document.querySelector(`.tab-content[data-tab="${tab}"]`).classList.add('active'); // 将当前选项卡标题设为活动状态 tabTitles.forEach(t => { t.classList.remove('active'); }); title.classList.add('active'); }); }); </script> </body> </html> ``` 这个示例代码创建了三个选项卡,每个选项卡都有一个标题和内容。通过JavaScript代码实现了点击选项卡标题时显示相应的内容,同时将当前选项卡标题设为活动状态。可以根据需要修改样式和添加更多选项卡

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值