# 元素位置

# jQuery 获取DOM

Element.offset().top 距离顶部 Element.offset().left 距离左边

$('a[href=#OMG]')[0].getBoundingClientRect().top

示意图

# 滚动位置

var sidebarScroll = $document.find('.J_sidebar_content').scrollTop() // 获取左栏滚动值


// 设定左边栏高度
function setSidebar(sidebarScroll) {
  var $sidebar = $document.find('.J_sidebar_content'),
      offsetTop = $sidebar.offset().top,
      windowHeight = $(window).height()

  $sidebar.css('height', windowHeight - offsetTop - 30 + 'px')
  if (sidebarScroll) {
    $sidebar.scrollTop(sidebarScroll)
  }
}

# 取数据data

$my_editor.attr('data-timestamp') //没有缓存 $my_editor.data('timestamp') // 有缓存

# 全屏

/*
 * 进入全屏
 */
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
 (!document.mozFullScreen && !document.webkitIsFullScreen)) {
  if (document.documentElement.requestFullScreen) {
    document.documentElement.requestFullScreen();
  } else if (document.documentElement.mozRequestFullScreen) {
    document.documentElement.mozRequestFullScreen();
  } else if (document.documentElement.webkitRequestFullScreen) {
    document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  }
} else {
  if (document.cancelFullScreen) {
    document.cancelFullScreen();
  } else if (document.mozCancelFullScreen) {
    document.mozCancelFullScreen();
  } else if (document.webkitCancelFullScreen) {
    document.webkitCancelFullScreen();
  }
}
}

// 启动全屏!
$document.on('keydown', function(e) {
 if (e.keyCode === 13) {
   e.preventDefault()
   console.log(e.keyCode)
   toggleFullScreen()
 }
})

$document.dblclick(function() {
 launchFullscreen(document.documentElement)
})
Last Updated: 5/14/2022, 11:38:45 AM