removeChild sometimes removes entire span and sometimes doesn't

泪湿孤枕 提交于 2019-12-04 11:42:32

I don't know if this will work on iOS, but if the position of the cursor means that there is a Selection at that point..

function moveToSelection(){
    var sel = document.getSelection(), // change the selection
        ran = sel.getRangeAt(0),       // into a range
        rec = ran.getClientRects()[0], // that we can get co-ordinates from
        dy  = rec.top;                 // distance to move down/up
    window.scrollBy( 0, dy );          // actual move

    // console.log( sel, ran, rec, y );   // help debug
}

moveToSelection();

Relevant links

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