簡體   English   中英

jQuery動畫在小提琴中工作但在線不流暢

[英]jQuery animate working in fiddle but not smooth online

我在小提琴中制作了一種帶有三個擴展div( #a#b#b #c )的手風琴,但是當我在本地保存並在瀏覽器中打開它時,過渡不再平滑。 點擊#b后我特意注意#a擴展。 我已經包含了引用CSS和JavaScript代碼的HTML。 原因是什么,解決它的最佳方法是什么?

<head>
     <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
     <link rel="stylesheet" href="style.css" />
</head>
<body>
    <div class="wrapper">
        <div class="outer">
            <div class="middle">
                <div class="inner" id="a">1</div> 
                <div class="inner" id="b">2</div> 
                <div class="inner" id="c">3</div> 
            </div>
        </div>
    </div>
    <script src="accordion.js"></script>
</body>

這是一個小提琴的鏈接: http//jsfiddle.net/tJugd/3794/

現在看來似乎只發生在任何#a擴大和#b#c被點擊或#b擴大和#c被點擊。

嘗試使用單個click事件處理程序用於與動畫.animate() easings屬性設置為"linear"css transition為效果中,設置width.middle div元素33%

 $(".middle div").click(function() { $(this).siblings().animate({ width: "10%", opacity: 0.6 }, 0, "linear"); $(this).animate({ width: "80%", opacity: 1 }, 0, "linear"); }); 
 div.inner { max-width: 0; display: table-cell; overflow: hidden; } div.outer { display: table; overflow: hidden; width: 100%; height: 100%; } div.middle { display: table-row; overflow: hidden; } #holder { width: 100%; height: 100%; margin: 0px auto; overflow: hidden; position: fixed; } #a { width: 33%; height: 100%; background-color: red; } #b { width: 33%; height: 100%; background-color: blue; } #c { width: 33%; height: 100%; background-color: green; } .wrapper { height: 90vh; overflow: hidden; } #a, #b, #c { transition: width 500ms, opacity 500ms; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <div class="wrapper"> <div class="outer"> <div class="middle"> <div class="inner" id="a">1</div> <div class="inner" id="b">2</div> <div class="inner" id="c">3</div> </div> </div> </div> 

jsfiddle http://jsfiddle.net/tJugd/3798/

試試這個

 window.onload = function() { [].forEach.call(document.querySelectorAll('.inner'), function(el) { el.addEventListener('click', function(e) { this.parentElement.className = 'middle ' + this.id; }); }); } //]]> 
 div.inner { max-width: 0; display: table-cell; overflow: hidden; } div.outer { display: table; overflow: hidden; width: 100%; height: 100%; } div.middle { display: table-row; overflow: hidden; } #holder { width: 100%; height: 100%; margin: 0px auto; overflow: hidden; position: fixed; } #a { height: 100%; background-color: red; } #b { height: 100%; background-color: blue; } #c { height: 100%; background-color: green; } #a, #b, #c { width: 10%; opacity: 0.6; transition: all 3000ms; } .middle.a #a, .middle.b #b, .middle.c #c { width: 80%; opacity: 1; } .wrapper { height: 90vh; overflow: hidden; } 
 <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>- jsFiddle demo</title> </head> <body> <div class="wrapper"> <div class="outer"> <div class="middle c"> <div class="inner" id="a">1</div> <div class="inner" id="b">2</div> <div class="inner" id="c">3</div> </div> </div> <div class="wrapper"> </div> </div> </body> </html> 

暫無
暫無

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

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