簡體   English   中英

在固定位置div上使用jquery淡入/淡出功能時,防止頁面自動向上滾動

[英]prevent automatically page scroll up when using jquery fadein/out founction on fixed position div

我有一個網頁,我想通過單擊一個按鈕來使div出現在屏幕右側(div和按鈕都具有固定位置),我使用jQuery fadein / out使其顯示

它工作正常,但是當我單擊按鈕時,頁面自動滑到頂部

htmlCode:

<div class="fixedDiv">
    <div class="fixedDiv liveSupportFrame" style="background: #f8aa00;display: none" id="lsf">
        <div class="container" style="background-color:#d8d6d6;">
        ............
        </div>
    </div>

    <a class="btn btn-warning sideBtn" onclick="showOrHideLiveSupport();" role="button" href="#">FAQ</a>

CSS代碼:

.fixedDiv{
position: fixed;
bottom: 25%;
right: 0em;
}
.fixedDiv .liveSupportFrame{
margin-right: 2em;
margin-bottom: 1em;
font-size:1.6vw;
bottom: 30%;
}

JS代碼:

        var isLsfOpen = 0;
    function showOrHideLiveSupport() {
       if(!isLsfOpen){
           showLiveSupport()
       }
       else{
           hideLiveSupport()
       }
    }
    function showLiveSupport() {
        $('#lsf').fadeIn();

        isLsfOpen=true;
    }
    function hideLiveSupport() {
        $('#lsf').fadeOut();
        isLsfOpen=false;
    }

那是因為href="#" 使用event.preventDefault(); 在您的處理程序中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM