2

次のように、ページの右側に固定 div があります。

ここに画像の説明を入力

これは私のhtmlです:

<a id="toggle" class="open"><img src="_styles/images/open_close.png" alt="openclose" /></a>
<div class="tweetdetails" style="width: 0px;">
  <p class="screenname">@BachelorGDM</p><br>
  <img src="linktoimage" alt="image_user"><br>
  <p class="createdon">Created on: Mar 8, 2013</p><br>
  <hr>
  <p class="text">Here is some text</p>
</div>

これは私のCSSです:

.tweetdetails{
  color:white;
  padding:10px 50px;
  position: fixed;
  right:0px;
  width:300px;
  z-index: 999;
  background-color: #FFF;
  height:100%;
  background-color: black;
      border-left: 5px solid rgb(127,255,255);
}

.open{
    background-repeat: no-repeat;
    background-size: 50px auto;
    color:red;
    position: fixed;
    right:400px;
    top:50%;
}

私のJavascriptには次のものがあります:

$("#toggle").click(function(){
    $(".tweetdetails").animate({width:'0px'}, 500);
    $("#toggle").animate({right: "-=300"}, 500);
})

しかし、私はいつもこのような結果を持っています: ここに画像の説明を入力

もう何も表示されないようにするにはどうすればよいですか? (パディングと関係があると思います...)

4

4 に答える 4

2

マジックナンバーなしで、より動的にすることができます:

 $(".tweetdetails").animate({width:'0px' , padding:'0px'}, 500);
 $("#toggle").animate({right: "-=" + ( $(".tweetdetails").outerWidth() ) }, 500);

.outerWidthwidth+padding+border、見てください:http
: //api.jquery.com/outerWidth/(@tbleckertのおかげで編集されました)

于 2013-06-19T08:32:17.020 に答える
1

これがあなたが望むものだと思います: http://jsfiddle.net/balintbako/XJbqD/

<a id="toggle" class="open"><img src="_styles/images/open_close.png" alt="openclose" /></a>

<div class="tweetdetails" style="width: 0px;">
    <p class="screenname">@BachelorGDM</p>
    <br/>
    <img src="linktoimage" alt="image_user"></img>
    <br/>
    <p class="createdon">Created on: Mar 8, 2013</p>
    <br/>
    <hr/>
    <p class="text">Here is some text</p>
</div>

CSS

.tweetdetails {
    color:white;
    position: fixed;
    right:0px;
    z-index: 999;
    background-color: #FFF;
    height:100%;
    background-color: black;
    border-left: 5px solid rgb(127, 255, 255);
}
.open {
    background-repeat: no-repeat;
    background-size: 50px auto;
    color:red;
    position: fixed;
    right:5px;
    top:50%;
}

JS

$("#toggle").click(function () {
    if ($("#toggle").hasClass("opened")) {
        $(".tweetdetails").animate({
            width: '0px',
            padding: '0px'
        }, 500);
        $("#toggle").animate({
            right: "-=" + 400
        }, 500);
    } else {
        $(".tweetdetails").animate({
            width: '300px',
            padding: '10px 50px'
        }, 500);
        $("#toggle").animate({
            right: "+=" + 400
        }, 500);
    }
    $("#toggle").toggleClass("opened");
});
于 2013-06-19T08:59:14.827 に答える
0
    $(".tweetdetails").css('padding', '10px 0').animate({width:'0px'}, 500);
于 2013-06-19T08:36:21.743 に答える