彼らはこのコードを構造化するためのよりクリーンな方法なのだろうか?? 戻るボタンと進むボタンの左右の値にデータ属性を使用したいと考えていました。
ありがとう!!!
.hover-area { position:relative; width:100%; height:50px; }
.backward, .forward { position:absolute; }
.backward{ left:0px; }
.forward { right:0px; }
<div class="hover-area">
Hover Area
<div class="backward" data-animate-on='{"left":"20"}' data-animate-off='{"left":"0"}'>
Previous
</div>
<div class="forward" data-animate-on='{"right":"20"}' data-animate-off='{"right":"0"}'>
Next
</div>
</div>
$('.forward').css({
opacity: 0,
right: 0
});
$('.hover-area').hover(function () {
$(this).find('.forward').stop().animate({
right: 20
}, {
queue: false,
duration: 300,
easing: 'easeOutCubic'
}).animate({
opacity: '0.95'
}, {
queue: false,
duration: 400,
easing: 'easeOutCubic'
});
}, function () {
$(this).find('.forward').stop().animate({
right: 0
}, {
queue: false,
duration: 550,
easing: 'easeOutSine'
}).animate({
opacity: '0'
}, {
queue: false,
duration: 300,
easing: 'easeOutSine'
});
});
$('.backward').css({
opacity: 0,
left: 0
});
$('.hover-area').hover(function () {
$(this).find('.backward').stop().animate({
left: 20
}, {
queue: false,
duration: 300,
easing: 'easeOutCubic'
}).animate({
opacity: '0.95'
}, {
queue: false,
duration: 400,
easing: 'easeOutCubic'
});
}, function () {
$(this).find('.backward').stop().animate({
left: 0
}, {
queue: false,
duration: 550,
easing: 'easeOutSine'
}).animate({
opacity: '0'
}, {
queue: false,
duration: 300,
easing: 'easeOutSine'
});
});