2013-08-05 16 views
1

我在製作一個閃爍的光標,我需要這個光標在數據的末尾閃爍(數據在幾秒鐘後出現)並附加在div中。現在我的光標位置是固定的。現在我需要將光標移動到爭論結束。這裏是嘗試。 http://jsfiddle.net/naveennsit/prUYP/如何在jquery中添加數據來移動遊標?

$(document).on('click', '#call', function(event) { 


    setInterval(function(){ 
    $('#realTimeContents').append("kkkkkkkkkk"+'\n'); 

    },3000); 
    setInterval(function(){ 

cursorAnimation(); 
    },600); 
}); 


function cursorAnimation() 
{ 
    // alert("yy") 
    $("div.cursor").animate(
    { 
    opacity: 0 
    }, "fast", "swing").animate(
    { 
    opacity: 1 
    }, "fast", "swing"); 
} 

我需要得到這樣的

kkkkkkk| 
KKKKKK KKKKKKKK| 

KKKKKk kkkkkkkk kkkkkkk| 

回答

0

你可以嘗試改變.cursor是 「跨度」,並添加它裏面#realTimeContents和變更追加的前面加上
HTML

<div data-role="page" id="realTimeScreen" > 
<a href="#" data-role="button" data-corners="false" data-inline="true" id="call" class="" >call</a> 
    <div id="realTimeContents" class ="left realtimeContend_h" style="width:97%;"> 
    <span class="cursor" style="font-size:23px;">|</span> 
    </div>      
</div>  

JS

$(document).on('click', '#call', function(event) { 
setInterval(function(){ 
    $('#realTimeContents').prepend("kkkkkkkkkk"+'\n'); 
    },3000); 
setInterval(function(){ 

cursorAnimation(); 
},600); 
}); 

function cursorAnimation() 
{ 
    $(".cursor").animate(
    { 
    opacity: 0 
    }, "fast", "swing").animate(
    { 
    opacity: 1 
    }, "fast", "swing"); 
}  

http://jsfiddle.net/prUYP/2/

+0

我還有一個問題..我可以問嗎? – user2648752

+0

是的,你可以問 –

+0

我需要滾動事件首先,當我滾動我的div我需要得到的事件在這裏是我的小提琴http://jsfiddle.net/naveennsit/x7ZyB/ – user2648752