2017-01-25 55 views
0

我想在滑塊上獲得很好的滑動效果(從左到右)。但它不適用於轉換和jQuery。滑動效果沒有工作

我的代碼有什麼問題嗎?

$(document).ready(function() { 
 
    $('.weiter').click(function() { 
 
    if ($('.eins').hasClass('active')) { 
 
     $('.eins').removeClass('active'); 
 
     $('.zwei').addClass('active'); 
 
    } else if ($('.zwei').hasClass('active')) { 
 
     $('.zwei').removeClass('active'); 
 
     $('.eins').addClass('active'); 
 
    } 
 
    }); 
 
});
header { 
 
    height: 250px; 
 
    width: 100%; 
 
    display: inline-block; 
 
    margin-bottom: 20px; 
 
} 
 
header section.eins { 
 
    background: url("http://www.petakids.com/wp-content/uploads/2015/07/sheep-and-lambs-in-field.jpg"); 
 
} 
 
header section.zwei { 
 
    background: url("https://aos.iacpublishinglabs.com/question/aq/700px-394px/long-sheep-pregnant_1b7dbe4ddad4dd1.jpg?domain=cx.aos.ask.com"); 
 
} 
 
header section { 
 
    height: 0; 
 
    visibility: hidden; 
 
    width: 0; 
 
    float: left; 
 
} 
 
header section.active { 
 
    float: left; 
 
    height: 100%; 
 
    width: 100%; 
 
    visibility: visible; 
 
} 
 
.weiter { 
 
    display: block; 
 
    cursor: pointer; 
 
    height: 50px; 
 
    background: red; 
 
    width: 50px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<header> 
 
    <i class="weiter"></i> 
 

 
    <section class="eins active"> 
 
    <span> 
 
    \t <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> 
 
\t </span> 
 
    </section> 
 

 
    <section class="zwei"> 
 
    <span> 
 
    \t <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> 
 
\t </span> 
 
    </section> 
 

 
</header>

+0

'有什麼錯誤的,我code' - 沒有錯誤,但沒有提出任何應 「滑動」 在都在javascript或css –

+0

你提到的'transition' css在哪裏? – Nope

回答

0

滑塊動畫從您的代碼失蹤。我可以使用元素的位置屬性添加一個簡單的幻燈片切換。

更新小提琴:https://jsfiddle.net/f31moo7y/1/

參考代碼:

$(document).ready(function() { 
 
    $('.weiter').click(function() { 
 
    if ($('.eins').hasClass('active')) { 
 
     $('.eins').removeClass('active'); 
 
     $('.zwei').addClass('active'); 
 
    } else if ($('.zwei').hasClass('active')) { 
 
     $('.zwei').removeClass('active'); 
 
     $('.eins').addClass('active'); 
 
    } 
 
    }); 
 
});
header { 
 
    height: 250px; 
 
    width: 100%; 
 
    display: inline-block; 
 
    margin-bottom: 20px; 
 
} 
 
header section.eins { 
 
    background: url("http://www.petakids.com/wp-content/uploads/2015/07/sheep-and-lambs-in-field.jpg"); 
 
} 
 
header section.zwei { 
 
    background: url("https://aos.iacpublishinglabs.com/question/aq/700px-394px/long-sheep-pregnant_1b7dbe4ddad4dd1.jpg?domain=cx.aos.ask.com"); 
 
} 
 
header section { 
 
    height: 0; 
 
    visibility: hidden; 
 
    width: 0; 
 
    float: left; 
 
    position: relative; 
 
    left: 100%; 
 
    transition: all .3s; 
 
} 
 
header section.active { 
 
    float: left; 
 
    position: relative; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 100%; 
 
    visibility: visible; 
 
} 
 
.weiter { 
 
    display: block; 
 
    cursor: pointer; 
 
    height: 50px; 
 
    background: red; 
 
    width: 50px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<header> 
 
    <i class="weiter"></i> 
 

 
    <section class="eins active"> 
 
    <span> 
 
    \t <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> 
 
\t </span> 
 
    </section> 
 

 
    <section class="zwei"> 
 
    <span> 
 
    \t <div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> 
 
\t </span> 
 
    </section> 
 

 
</header>