[この質問を最初に投稿した方法についてお詫びします!]
私はポートフォリオ タイプの Web サイトを作成しており、「最近の作業」セクションの項目をクリックしたときに表示されるような効果が必要です: http://themes.zenthemes.net/cleanr/
基本的に、これは私が達成しようとしている機能です:
- アイテムのリンクをクリックします (複数のアイテムには異なるコンテンツへのリンクがあります)
- クリックすると、div がアニメーション化され、新しいコンテンツが (事前に定義された場所で) 開きます
- 開く div には閉じるボタンがあります。閉じるボタンをクリックすると、DIV がアニメーション化して閉じます。
- 一度に表示できるのは、新しいコンテンツを含むこれらの div の 1 つだけです。したがって、2 番目のリンクをクリックすると、最初の div がすぐに閉じて、2 番目の div が開くはずです。
私は以下のコードで解決策にかなり近づいていますが、1 つの大きな不具合が発生しています...
DIV 1 を開いてから DIV 2 を開くと、DIV 1 を折りたたむ/非表示にすることが認識されます。これは完璧です (したがって、一度に 1 つの div のみが表示されます)。
ただし、DIV 1 を開いて DIV 1 の閉じる (赤い X) ボタンをクリックすると、閉じ始めますが、閉じるとすぐに再び開きます。閉じて閉じたままにしたいだけです(リンクが再度クリックされるまで)。
いろいろ試してみましたが、うまく再生できません。
ここで実際にこれを見ることができます: http://jsfiddle.net/tdHTN/1/
(最初の「実行」ボタンをクリックしてから、表示される赤い「x」をクリックして問題を確認してください。)
ここに私のCSSがあります:
#slidingDiv, #slidingDiv_2{
height:200px;
background-color: #99CCFF;
padding:20px;
margin-top:10px;
border-bottom:5px solid #3399FF;
display:none;}
ここに私のHTMLがあります:
<div id="slidingDiv" class="toggleDiv" style="clear:both;">
This is my content for block ONE (1). Isn't it so super interesting?
<a href="#" class="show_hide" rel="#slidingDiv"><img src="https://cdn2.iconfinder.com/data/icons/officeicons/PNG/48/Close.png" width="48" height="48" alt="close" /></a>
<div id="slidingDiv_2" class="toggleDiv" style="clear:both;">
This is some super exciting content that I will fill in later. This is block TWO (2)
<a href="#" class="show_hide" rel="#slidingDiv_2"><img src="https://cdn2.iconfinder.com/data/icons/officeicons/PNG/48/Close.png" width="48" height="48" alt="close" /></a>
<a href="#" class="show_hide" rel="#slidingDiv"><img src="https://www.bcidaho.com/_images/go-button-trans.gif" alt="Play" width="42" height="41" border="0" align="left" /></a>
<a href="#" class="show_hide" rel="#slidingDiv_2"><img src="https://www.bcidaho.com/_images/go-button-trans.gif" alt="Play" width="42" height="41" border="0" align="left" /></a>
これが私のJSです:
(function ($) {
$.fn.showHide = function (options) {
//default vars for the plugin
var defaults = {
speed: 1000,
easing: '',
changeText: 0,
showText: 'Show',
hideText: 'Hide'
};
var options = $.extend(defaults, options);
$(this).click(function () {
$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which div id to toggle
var toggleDiv = $(this).attr('rel');
// here we toggle show/hide the correct div at the right speed and using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
}
});
return false;
});
};
})(jQuery);
$(document).ready(function(){
$('.show_hide').showHide({
speed: 1000, // speed you want the toggle to happen
easing: ''
});
});
私が達成しようとしているもう 1 つのこと (可能であれば) は、DIV アニメーションを下にスライドさせるのではなく、上にスライドさせることです。「slideUp」を「slideDown」に変更してみましたが、うまくいきませんでした。
ご協力いただきありがとうございます。
[注: スクリプト ソース: http://papermashup.com/jquery-show-hide-plugin/]