一か念う执着が 2022-10-23 19:47 采纳率: 94.1%
浏览 43
已结题

轮播图切换问题,和谷歌浏览器闪图

各位恕我无能,我不知道为什么程序没问题,在火狐上能正常的进行轮播和点击上下切换,不会闪,但是在谷歌和微软的新浏览器就会出现一次直接轮不三张图才停三秒钟,在最后一张切回第一张时会闪一下。火狐上和微软老浏览器IE上一点问题都没有

img


<div class="RotationChartAndLoginBox">
                    <div id="RotationChartModule">
                        <div class="PictureRotation">
                            <div id="tation_imgBox" style="width: 3990px;overflow:hidden;transition:all 0.3s;transform: translateX(0px);position: absolute;backface-visibility:hidden;">
                                <div class="tation_img" style="float:left;width:564px;" data-rotaion="0"><a href=""><img src="./imge/O1CN011yBJBI1FtCEaHaebh_!!6000000000544-2-octopus.png" alt=""></a></div>
                                <div class="tation_img" style="float:left;width:564px;" data-rotaion="1"><a href=""><img src="./imge/O1CN013jhNY51VGkqFZezAz_!!6000000002626-0-octopus.jpg" alt=""></a></div>
                                <div class="tation_img" style="float:left;width:564px;" data-rotaion="2"><a href=""><img src="./imge/O1CN01uFc5A720osRJbUXo9_!!6000000006897-2-octopus.png" alt=""></a></div>
                                <div class="tation_img" style="float:left;width:564px;" data-rotaion="3"><a href=""><img src="./imge/O1CN01q68omo1PFU3CIDAub_!!6000000001811-2-octopus.png" alt=""></a></div>
                                <div class="tation_img" style="float:left;width:564px;" data-rotaion="4"><a href=""><img src="./imge/O1CN01VCxO9H1ujwTZEUBOU_!!6000000006074-0-octopus.jpg" alt=""></a></div>
                            </div>
                            <ul class="RotationDot_Dot">
                                <li class="rotation_Dot active"  data-tation="0"></li>
                                <li class="rotation_Dot"  data-tation="1"></li>
                                <li class="rotation_Dot"  data-tation="2"></li>
                                <li class="rotation_Dot"  data-tation="3"></li>
                                <li class="rotation_Dot"  data-tation="4"></li>
                            </ul>
                            <div class="btn" style="visibility:hidden;">
                                <button class="leftButton"><i class="leftIcon"></i></button>
                                <button class="rightButton"><i class="rightIcon"></i></button>
                            </div>
                        </div>
                    </div>

function tation(){
    var PictureRotation = document.querySelector('.PictureRotation');
    var leftButton = document.getElementsByClassName('leftButton')[0]; 
    var rightButton = document.getElementsByClassName('rightButton')[0];
    var tation_imgBox = PictureRotation.children[0];//获取父级元素下面的子元素(又名节点)
    var width = PictureRotation.offsetWidth;
    var RotationDot_Dot = PictureRotation.children[1];
    var btn = document.getElementsByClassName('btn')[0];
    var index = 0;
    var btnClick = true;
    tation_imgBox.style.left = '-564px';
    tation_imgBox.appendChild(tation_imgBox.children[4].cloneNode(true));//克隆4号节点解决insertBefore复制html原有的4号节点的位置空缺
    tation_imgBox.appendChild(tation_imgBox.children[0].cloneNode(true));//克隆
    tation_imgBox.insertBefore(tation_imgBox.children[4] , tation_imgBox.children[0]);
    var timer = setInterval(function(){   
        index++;    
        TranSlate();
    },3000);
    tation_imgBox.addEventListener('transitionend',function(){
        if(index >= 5){
            index = 0;
            tation_imgBox.style.transition = 'none';
            var translatex = -index * width;
            tation_imgBox.style.transform = 'translateX(' + translatex + 'px)';
        }else if(index < 0){
            index = 4;
            tation_imgBox.style.transition = 'none';
            var translatex = -index * width;
            tation_imgBox.style.transform = 'translateX(' + translatex + 'px)';
        };
        QuerySelector();
    });
    PictureRotation.onmouseover = function(){
        btn.style.visibility = 'visible';
        clearInterval(timer);
    };
    PictureRotation.onmouseout = function(){
        btn.style.visibility = 'hidden';
        timer = setInterval(function(){
            index++;
            TranSlate();
        },3000); };
        RotationDot_Dot.addEventListener('click',function(e){
            var e = e || window.event;
             var inX = e.target || e.srcElement; 
            if(inX.className == 'rotation_Dot') {  
                index  = inX.getAttribute('data-tation') || inX.dataset.tation;  
                TranSlate();
                QuerySelector();
            };
        });
        rightButton.addEventListener('click',function(){
            if(btnClick){
                btnClick = false;
                index++;
                clearInterval(timer);
                TranSlate();
                setTimeout(function(){
                    btnClick = true;
                },700);
            }else{
                return false;
            };
            });
            leftButton.addEventListener('click',function(){
                if(btnClick){
                    btnClick = false;
                    index--;
                    clearInterval(timer);
                    TranSlate();
                    setTimeout(function(){
                        btnClick = true;
                    },700);
                }else{
                    return false;
                     };
                    });
    function TranSlate(){
       var translatex = -index*width;
       tation_imgBox.style.transition = 'all 0.3s';
       tation_imgBox.style.transform = 'translateX(' + translatex + 'px)';};
       function QuerySelector(){
        RotationDot_Dot.querySelector('.active').classList.remove('active');
        RotationDot_Dot.children[index].classList.add('active');
        }
    };
.RotationChartAndLoginBox{
    width: 882px;
    height: 357px;
}
#RotationChartModule{
    width: 564px;
    height: 315px;
    margin-top: 10px;
    position: relative;
    float: left;
}
.PictureRotation{
    width: 564px;
    height: 315px;
    position: relative;
    border-radius: 10px;
    overflow: hidden;
}
.tation_imgBox{
    position: absolute;
    transition-duration: 1s;
}
.tation_img{
    position: relative;
}
.tation_img img{
    width: 564px;
    height: 315px;
    display: block;
    border-radius: 10px;
    opacity: 1;
}
.tation_img.active{
    z-index: 10;
    opacity: 1;
}
.RotationDot_Dot{
    position: absolute;
    left: 244px;
    width: auto;
    height: 9px;
    z-index: 13;
    top: 290px;
    padding: 3px 5px;
    background-color: rgba(255, 255, 255, .3);
    border-radius: 50px;
    
}
.rotation_Dot{
    width: 9px;
    height: 9px;
    background-color: #fff;
    float: left;
    margin: 0 3px;
    border-radius: 50px;
    cursor: pointer;
}
.rotation_Dot.active{
    background-color: #ff5000;
}
.leftButton{
    width: 20px;
    height: 30px;
    border-bottom-right-radius: 50px;
    border-top-right-radius: 50px;
    background-color: rgba(40, 38, 38, 0.2);
    position: absolute;
    top: 130px;
    left: 0;
    z-index: 40;
    border: none;
    cursor: pointer;
    
}
.leftButton:hover{
    background-color: rgba(40, 38, 38, 0.5);
}
.leftIcon{
    line-height: 30px;
    font-size: 12px;
    color: #fff;
    font-weight: 900;
    font-style: normal;
    position: absolute;
    left: 2px;
    top: 0px;
}
.rightButton{
    width: 20px;
    height: 30px;
    border-bottom-left-radius: 50px;
    border-top-left-radius: 50px;
    background-color: rgba(40, 38, 38, 0.2);
    position: absolute;
    top: 130px;
    right: 0;
    z-index: 40;
    border: none;
    cursor: pointer;
}
.rightButton:hover{
    background-color: rgba(40, 38, 38, 0.5);
}
.rightIcon{
    line-height: 30px;
    font-size: 12px;
    color: #fff;
    font-weight: 900;
    font-style: normal;
    position: absolute;
    right: 1px;
    top: 0;
}
#UserloginDisplayBox{
    width: 316px;
    height: 357px;
    position: relative;
    float: left;
}
.UserLogobox{
    position: relative;
}

  • 写回答

1条回答 默认 最新

  • 夜郎king 2022博客之星IT其它领域TOP 12 2022-10-24 09:15
    关注

    这种一般是浏览器兼容性问题,火狐和谷歌对于样式的标准不太一致。如果不是为了学习,可以找一个开源兼容性强的插件,来辅助解决。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 已采纳回答 10月26日
  • 创建了问题 10月23日

悬赏问题

  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。