增加了一个tab标签,但是点击的时候第二个标签并不显示,点击第四个标签,结果第二个变色,并且根据滚动位置显示不同的tab
//以前代码
<div class="topboxs yx_home"></div>
<div class="topbox" id="thetitle" style="display:none;">
<div class="toptitle topselect">产品介绍
<span class="selectspan"></span>
</div>
<div class="toptitle">产品流程
<span class="selectspan"></span>
</div>
<div class="toptitle">产品问题
<span class="selectspan"></span>
</div>
</div>
<!-- syx-首页改造 -->
<div id="index">
<img id="pro_img"/ onload="loadImage()">
<div class="yxhomebox">
</div>
</div>
//现在代码
<div class="topboxs yx_home"></div>
<div class="topbox" id="thetitle" style="display:none;">
<div class="toptitle topselect">产品链接
<span class="selectspan"></span>
</div>
<div class="toptitle">产品介绍
<span class="selectspan"></span>
</div>
<div class="toptitle">产品流程
<span class="selectspan"></span>
</div>
<div class="toptitle">产品问题
<span class="selectspan"></span>
</div>
</div>
<!-- syx-首页改造 -->
<div id="index">
<div class="top_home_ybtx" id="top_home">
<p>xx产品信息一共<span>X个</span>系统将使用家庭单计算费用。
1.请逐一填写下方链接,待所有链接填写完成后,再统一提交订单,系统将逐笔扣款,生成X个投保单。
2.第一个链接填写完成后,才能填写后续链接,且信息自动同步,若需修改信息,需返回第一个链接修改。</p>
<ul class="top_home_ybtx_tip">
<li class="top_home_ybtx_tips">
<img />
<div class="top_home_ybtx_div">
<p class="top_home_ybtx_divp">发发发(瑞臻版)</p>
</div>
</li>
</ul>
</div>
<img id="pro_img"/ onload="loadImage()">
<div class="yxhomebox">
</div>
</div>
//syx-营销首页改造
if(filurl[1]=="YINGXIAO"||filurl[1]=="EMT"){
$(".qr_box").hide();
$(".ewmimg").show();
$("#index").css("paddingBottom","2.2rem");
if(productId){
$("#thetitle").show();
}else{
$(".yx_home").show();
$("#twotitle").show();
$("#thetitle").remove();
}
if(!is_agent){
$(".bottom_box").hide();
$(".toptitle").width("25%");
}else{
$(".commom_position_bottom").hide();
$(".toptitle").width("25%");
}
}else{
$("#index").css("height",$(window).height()-$(".bottom_box").height());
}
function yxhome(){
if(filurl[1]=="YINGXIAO"||filurl[1]=="EMT"){
$("#index").css("height",$(window).height()-$(".bottom_box").height());
$(".yxhomebox").html("");
$(".yxhomebox").append('<div class="lpbox yx_home"><img src="images/lpbox.jpg"></div><div class="quest_box yx_home"><img src="images/cjwt.jpg" style="margin-left:-0.4rem;"><ul> </ul></div>')
$(".yx_home").show();
if(!is_agent){
$(".bottom_box").hide();
}else{
$(".commom_position_bottom").hide();
}
if(productId){
// 常见问题
$.ajax({
type: "post",
url:commonurl+"queryCommonProblem",
data:JSON.stringify({"productId":productId}),
contentType: "application/json",
success: function(data){
if(data.result_code==0){
if(data.problems){
for(var i=0;i<data.problems.length;i++){
$(".quest_box ul").append('<li><div class="quest_boxs"><img class="quest_icon" src="images/quest.jpg"><div class="quest_info">'+data.problems[i].problem+'</div><img class="quest_up" src="images/icon_arrow_bottom.png"></div><div class="answer">'+data.problems[i].answer+'</div></li>')
}
$(".quest_box .quest_boxs").click(function(){
if($(this).next(".answer").css("display")=="none"){
$(this).find(".quest_up").css("transform","rotate(180deg)");
$(this).next(".answer").show();
var tagname=$(this).next(".answer").children().attr("tagName");
$(this).next(".answer").children(tagname).eq(0).prepend('<img class="quest_icon answer_icon" src="images/answer.jpg">');
}else{
var tagname=$(this).next(".answer").children().attr("tagName");
$(this).next(".answer").children(tagname).eq(0).find(".quest_icon").remove();
$(this).find(".quest_up").css("transform","rotate(0deg)");
$(this).next(".answer").hide();
}
})
}
funcReadImgInfo()
}else{
$("#thetitle").remove();
$("#twotitle").show();
$(".quest_box").hide();
$(".selectspan").eq(0).show();
productId=null;
$("#index").css("paddingBottom","1.8rem");
}
}
})
}else{
$(".quest_box").hide();
$("#index").css("paddingBottom","1.8rem");
}
var topclick=0;
$(".selectspan").eq(0).show();
$(".toptitle").click(function(){
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
$(this).addClass("topselect");
$(this).find(".selectspan").show();
if($(this).index()=="0"){
topclick=1;
$("#index").scrollTop(0);
}else if($(this).index()=="1"){
var imgheight=$("#pro_img").height();
$("#index").scrollTop(imgheight-10);
topclick=2;
}else if($(this).index()=="2"){
var imgheight=$("#top_home").height()+$("#pro_img").height();
topclick=3;
}else if($(this).index()=="3"){
var imgheight=$("#top_home").height()+$("#pro_img").height()+$(".lpbox").height();
$("#index").scrollTop(imgheight-10);
topclick=4;
}
})
//监听滚动事件
document.getElementById('index').onscroll = function() {
var topheight=$("#top_home").height();//客户端
var imgheight=$("#pro_img").height();
var lpboxheight=$(".lpbox").height();
if(!productId){
if($("#index").scrollTop()<imgheight){
if(topclick==2){
$(".toptitle").eq(1).addClass("topselect");
$(".toptitle").eq(1).find(".selectspan").show();
return;
}
if($(".toptitle").eq(0).attr("class")=="toptitle toptitles topselect"){
return;
}
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
$(".toptitle").eq(0).addClass("topselect");
$(".toptitle").eq(0).find(".selectspan").show();
}
if($("#index").scrollTop()>=imgheight){
if($(".toptitle").eq(1).attr("class")=="toptitle toptitles topselect"){
return;
}
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
$(".toptitle").eq(1).addClass("topselect");
$(".toptitle").eq(1).find(".selectspan").show();
}
}else{
if($("#index").scrollTop()<imgheight){
if($(".toptitle").eq(0).attr("class")=="toptitle topselect"){
return;
}
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
if(topclick==3){
$(".toptitle").eq(1).addClass("topselect");
$(".toptitle").eq(1).find(".selectspan").show();
}else{
$(".toptitle").eq(0).addClass("topselect");
$(".toptitle").eq(0).find(".selectspan").show();
}
}
if($("#index").scrollTop()>=imgheight&&$("#index").scrollTop()<(imgheight+lpboxheight)){
if($(".toptitle").eq(1).attr("class")=="toptitle topselect"){
return;
}
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
if(topclick==3){
$(".toptitle").eq(2).addClass("topselect");
$(".toptitle").eq(2).find(".selectspan").show();
}else{
$(".toptitle").eq(1).addClass("topselect");
$(".toptitle").eq(1).find(".selectspan").show();
}
}
if($("#index").scrollTop()>(imgheight+lpboxheight)){
if($(".toptitle").eq(2).attr("class")=="toptitle topselect"){
return;
}
$(".toptitle").removeClass("topselect");
$(".selectspan").hide();
$(".toptitle").eq(2).addClass("topselect");
$(".toptitle").eq(2).find(".selectspan").show();
}
}
};
}
}
function loadImage(){
yxhome();
}
.yx_home{
display: none;
background:white;
}
.topboxs{
width: 100%;
height: 1.8rem;
z-index:10;
}
.topbox{
display: flex;
align-content: center;
height: 1.8rem;
position: fixed;
top:0;
left: 0;
right: 0;
z-index:10;
background:white;
}
.toptitle{
display: inline-block;
position:relative;
text-align: center;
line-height: 1.8rem;
font-size: 0.7rem;
font-weight: 500;
width: 25%;
flex-shrink: 0;
}
.toptitles{
width: 50%;
}
.topselect{
color: #029dff;
}
.selectspan{
width: 20%;
height: 0.12rem;
background: #029dff;
position: absolute;
left: 40%;
bottom: 0;
border-radius: 0.1rem;
display: none;
}