Jquery how to change text value of div with an effect

ε祈祈猫儿з 提交于 2019-12-13 08:39:42

问题


I am able to change inside of div with the following code

$(".mydivclass").html("my data");

Now if possible i want to add an effect like show (delay) or something other. How can i do that when changing the data inside div. Thank you


回答1:


A little simple example using fading effect.

HTML

<div id="sometext">
    Start text 
</div>

JS

$("#sometext").fadeOut(function() {
  $(this).text("change!").fadeIn();
});

Fiddle on : http://jsfiddle.net/uxhE2/




回答2:


Basically what you need to do is chaining different jquery methods. E.g. this would be a simple hide and show effect.

$(".mydivclass").hide().html("my data").show('slow');

If you prefer some hiding effect, which is time based, you need to define your "show" effect inside a callback, like PeeHaa illustrated. Otherwise the effects won't be "queued" and the show effect will start before the hiding has finished.




回答3:


You could add an element dynamically and made the content fade in

$("<span id='myData'>my data</span>").hide().appendTo(".mydivclass");
$("#myData").fadeIn()

Here's an example : http://jsfiddle.net/MqhdG/




回答4:


Because you say any effect what about:

$(".mydivclass").slideUp('slow', function() {
  $(".mydivclass").html('data');
  $(".mydivclass").slideDown('slow');
});


来源:https://stackoverflow.com/questions/8202087/jquery-how-to-change-text-value-of-div-with-an-effect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!