0

の幅を取得してdiv.newsticker 、アニメーションと追加の変数として使用しようとしています。

ただし、これは機能していないようです。どうすれば修正できますか?

これは私のコードです。

jQuery(document).ready(function () {
    var width = jQuery("div.newsticker").width()+"px";
}); 

// To get resize notification
jQuery(window).on("resize", function() {
   var width = jQuery(".newticker").width()+"px";
});

function showComments(time){
    var comments = findComments(time);
    if(comments[0]){
        $('.newsticker p').animate({"marginLeft":width,"opacity":".0"}, 600).fadeOut(100);
        $('.newsticker').append("<p style='margin-left:"+width+";opacity:0'>"+comments[0].message+"</p>");
        $('.newsticker p').animate({"marginLeft":"0px","opacity":"1"}, 600);
    }
}

元のコード

function showComments(time){
    var comments = findComments(time);
    if(comments[0]){
        $('.newsticker p').animate({"marginLeft":"400px","opacity":".0"}, 600).fadeOut(100);
        $('.newsticker').append("<p style='margin-left:400px;opacity:0'>"+comments[0].message+"</p>");
        $('.newsticker p').animate({"marginLeft":"0px","opacity":"1"}, 600);
    }
}
4

1 に答える 1