我需要帮助重写我的 jQuery。我在顶部有四个链接:“一、二、三、四”
当您从一-> 二走时,它会从右侧擦除。完美的!
当您从二 --> 一开始时,它会从右侧擦入。不理想。我希望它从左侧滑入。
依此类推。这容易吗?
http://jsfiddle.net/5N3YK/126/
HTML:
<a data-section="one" href="#">One</a>
<a data-section="two" href="#">Two</a>
<a data-section="three" href="#">Three</a>
<a data-section="four" href="#">Four</a>
<div id="hello">
<section id="one" class="active">One</section>
<section id="two">Two</section>
<section id="three">Three</section>
<section id="four">Four</section>
</div>
CSS:
#hello, #hello section{
min-width: 350px;
height:330px;
background:green;
}
#hello section{
position: absolute;
left:100%;
}
#hello{
position: relative;
overflow: hidden;
width:90%;
}
#hello section:nth-child(1){left:0%}
jQuery:
$('a').on('click', function(event) {
event.preventDefault();
var sectionId = $(this).attr("data-section"),
$toSlide = $("#hello section#" + sectionId),
$fromSlide = $('.active');
if (!($toSlide.hasClass("active"))) {
$fromSlide.animate({
"left": "-100%"
}, 500, 'linear')
$toSlide.animate({
"left": "0%"
}, 500, 'linear', function() {
$fromSlide.css("left", "100%");
$fromSlide.removeClass("active");
$toSlide.addClass("active");
});
}
});