すべての画像は320pxです。中央のjQueryアコーディオン(幅はjQueryで計算されます)は奇妙な動作を表示します!
デフォルトでは、コンテナの幅(アンカータグ)は78px
に設定されています。
アンカータグを1つホバーすると、310px
に展開されます。
私はそれらを中心にしたいと思っていました。margin: 0 auto
〜#accordion ul
です。
センターを整えるために、固定幅を#accordion ul
に指定できませんでした。だから私は動的にjQueryでその幅を計算しました。
しかし、アンカータグを置くと、全体の幅が変わります(1つの画像は310pxに拡大されます)。 310-78px
(私の数学が正しいかどうかわからない)をする必要があります。私は最後の画像を合わせると
それは動作しますが、
- は、私はいくつかの奇妙な振る舞いを取得します。
#accordion ul
は、カーソルを置くまで中央に配置されません(デフォルトで中央に配置する必要があります)。
あなたはここでそれを確認することができます:http://alexchen.info/brianfunshine/
任意の提案を?
JS:
var $j = jQuery.noConflict();
$j(document).ready(function() {
/**
* jQuery Accordion
*/
$j('#accordion ul li a').hover(function() {
// if the element is currently being animated (to a easeOut)...
if ($j(this).is(':animated')) {
$j(this).stop().animate({width: "310px"}, {duration: 450, easing:"easeOutQuad"});
} else {
// ease in quickly
$j(this).stop().animate({width: "310px"}, {duration: 400, easing:"easeOutQuad"});
}
}, function() {
// on hovering out, ease the element out
if ($j(this).is(':animated')) {
$j(this).stop().animate({width: "78px"}, {duration: 400, easing:"easeInOutQuad"})
} else {
// ease out slowly
$j(this).stop('animated:').animate({width: "78px"}, {duration: 450, easing:"easeInOutQuad"});
}
});
/**
* Calculate the size of all the images inside the Jquery Accordion
*/
var customWidth = $j('#accordion ul li a').outerWidth(true);
var customNumber = $j('#accordion ul li a').size();
// add extra 78px if it is hovered
$j('#accordion ul li a').hover(function() {
$j('#accordion ul').css('width', (customWidth*customNumber+242) + 'px');
}, function() {
var cssObj = {
'width' : customWidth*customNumber,
}
$j('#accordion ul').css(cssObj);
});
});
は、HTML:
<div id="accordion">
<ul>
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=page_content&page_sections=Slider (Front Page)');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?>
<li class="landscapes"><?php the_content(); ?><></li>
<?php endwhile; ?>
</ul>
</div>
私はここで瞬時にそれを解読しますが、確かに、実際には「人物」タブを2回生成する予定ですか? – lsuarez
ちなみに、ホバーアニメーションがどこかに拘束されているかどうかはわかりませんが、自分で作ったかどうかはわかりませんが、本当に楽しかったです!かなり賢い。 :] – lsuarez