javascript - Repeating fadein on news feed -
a page of website has news feed use ajax return each day 1 @ time , display it. want each days news appear fade in.
the problem fade in repeats, each day return
html
<div id='newsdiv' class='newsdiv'></div>
javascript ajax call
document.getelementbyid('newsdiv').innerhtml += xmlhttp.responsetext;
css
@keyframes fadein { { opacity: 0; } { opacity: 1; } } /* firefox < 16 */ @-moz-keyframes fadein { { opacity: 0; } { opacity: 1; } } /* safari, chrome , opera > 12.1 */ @-webkit-keyframes fadein { { opacity: 0; } { opacity: 1; } } /* internet explorer */ @-ms-keyframes fadein { { opacity: 0; } { opacity: 1; } } /* opera < 12.1 */ @-o-keyframes fadein { { opacity: 0; } { opacity: 1; } } .divfadein, .centrescreen, .tbl_houseform { -webkit-animation: fadein 3s; /* safari, chrome , opera > 12.1 */ -moz-animation: fadein 3s; /* firefox < 16 */ -ms-animation: fadein 3s; /* internet explorer */ -o-animation: fadein 3s; /* opera < 12.1 */ animation: fadein 3s; -webkit-animation-iteration-count: 1; -moz-animation-iteration-count: 1; -ms-animation-iteration-count: 1; -o-animation-iteration-count: 1; animation-iteration-count: 1; -webkit-animation-fill-mode: forwards; -moz-animation-fill-mode: forwards; -ms-animation-fill-mode: forwards; -o-animation-fill-mode: forwards; animation-fill-mode: forwards; }
if put fade in parent new feed, it'll fade in when first day returned, not of following days.
if put fade in on child div, it'll fade in when each , every day returned (i.e. repeating fade in when next day returned).
how stop happening? how stop each day fading in more once?
i understand each day fading in because div "divnews" being re-populated. understanding doesn't solve problem.
you should append new element in parent div instead of updating whole content.
you can return json ajax call , create new element on fly returned data on callback function.
a simple example using jquery :
$.get('your_url',function(data){ var el = $('<div></div>').addclass('animation_class').html(data.key); $('#newsdiv').append(el); });
Comments
Post a Comment