2016-11-27 2 views
0

私はjqueryの応答でこれを持っている:<h3 id="5" class="headline-content">Some headline </h3> 私は左から入るように見えるように、私はデータをスライドすることができますどのように思ったんだけど:dataが似ているjQuery replaceWithで要素をスライドさせる方法は?

... 
     success: function(data) { 
     $(".headline").replaceWith(function() { 
      return $(data).hide().fadeIn(); 
     }); 

答えて

1

このソリューションはJQueryとJQuery UI(スライド左効果用)を使用しています。ここでは、function test(data)があなたの成功関数になります。 replaceWithは必要ありません。

var d = "<h3>Some headline </h3>"; 
 
test(d); 
 

 
function test(data) { 
 
    // Inject the result into the DOM element, but hide it at the same time 
 
    $(".headline").hide().html(data); 
 

 
    // toggle the visibility and animate the element coming in from the right 
 
    $(".headline").toggle("slide", {direction: "right"}); 
 
} 
 
.headline { font-size:2em; 
 
    width: 300px; 
 
    height: 2em; 
 
    background: #ccc; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script type = "text/javascript" 
 
     src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> 
 
<div class="headline"></div>

+0

まあこれは最初のテキストが消えてしまいます。また、私は実際に〜250KBのjquery-ui.jsをこのスライダーを使用するのに使用しないことを好みます。それを避ける方法はありませんか? – Karlom

+1

@カロムテキストを消す必要はありません。 '.hide()'命令を削除するだけです。私はちょうどこれがあなたが探していたものだと思った。そして、あなたはJQuery UIを使う必要はありませんが、自分のスライドを書くことは、それが価値あるものよりも難しいかもしれません。 –

関連する問題