我知道我的代码可能会像现在一样短。但我只是不知道如何缩短它。我想这样做是因为它让一切变得更清晰。此外,这段代码使一切变得比它需要的更慢。
html
<div id="slider">
<div id="slideLeft">
<div class="slideText">
<h1>Ik zoek werk</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse iaculis magna sed lacus vestibulum venenatis.
Quisque sem turpis, semper vitae gravida sit amet, tristique ut ligula.
</p>
<div class="slideButton">Bekijken</div>
</div>
<img src="../_/img/slidetest.png" />
</div>
<div id="slideRight">
<div class="slideText">
<h1>Ik zoek personeel</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse iaculis magna sed lacus vestibulum venenatis.
Quisque sem turpis, semper vitae gravida sit amet, tristique ut ligula.
</p>
<div class="slideButton">Bekijken</div>
</div>
<img class="slideImgSolid" src="../_/img/slidetest3.png" />
</div>
</div>
css
#slider{width:100%;min-height:450px;background-color:#999;}
#slideLeft{width:50%;position:absolute;left:0;background-color:#333;height:450px;overflow:hidden;}
#slideRight{width:50%;position:absolute;right:0;height:450px;background-color:#666;overflow:hidden;}
.slideText{position:absolute;top:50%;overflow:hidden;width:400px;z-index:100;}
#slideLeft .slideText{right:0;}
#slideRight .slideText{left:-150px;}
#slider h1{position:relative;font-size:18px;background-color:white;padding:5px 15px 5px 15px;}
#slideRight .slideText h1{text-align:right;left:0px;}
#slideLeft .slideText h1{text-align:left;right:-150px;}
#slider p{position:relative;width:300px;right:-400px;margin:20px 0 0 0;}
.slideButton{position:relative;right:0;right:-400px;margin:10px 0 0 0;background-color:#888;width:70px;padding:5px;text-align:center;}
.slideImgSolid{position:absolute;top:0;right:0;}
js
$('#slideLeft').mouseenter(function(){
$("#slideRight").animate({
width: '30.1%',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft p").animate({
right: '0px',
easing: 'easInOutCubic'
}, { duration: 100, queue: false });
$("#slideLeft h1").animate({
right: '0px',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft .slideButton").animate({
right: '0px',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft").animate({
width: '70%',
easing: 'easInOutCubic',
}, { duration: 200, queue: false });
});
$('#slideLeft').mouseleave(function(){
$("#slideRight").animate({
width: '50%',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft h1").animate({
right: '-150px',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft p").animate({
right: '-400px',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
$("#slideLeft .slideButton").animate({
right: '-400px',
easing: 'easInOutCubic'
}, { duration: 100, queue: false });
$("#slideLeft").animate({
width: '50%',
easing: 'easInOutCubic'
}, { duration: 200, queue: false });
});