社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Community Fernando Kosh

Community Fernando Kosh 最近创建的主题
Community Fernando Kosh 最近回复了
9 年前
回复了 Community Fernando Kosh 创建的主题 » 当内容位于可见视区时启动jquery动画

一个基于 this answer 检查一个元素是否75%可见(即屏幕上显示的元素少于25%)。

function isScrolledIntoView(el) {
  // check for 75% visible
  var percentVisible = 0.75;
  var elemTop = el.getBoundingClientRect().top;
  var elemBottom = el.getBoundingClientRect().bottom;
  var elemHeight = el.getBoundingClientRect().height;
  var overhang = elemHeight * (1 - percentVisible);

  var isVisible = (elemTop >= -overhang) && (elemBottom <= window.innerHeight + overhang);
  return isVisible;
}
9 年前
回复了 Community Fernando Kosh 创建的主题 » 当内容位于可见视区时启动jquery动画

建造 this great answer ,您可以使用ES2015+进一步简化它:

function isScrolledIntoView(el) {
  const { top, bottom } = el.getBoundingClientRect()
  return top >= 0 && bottom <= window.innerHeight
}

如果你不在乎顶部从窗口出来,只在乎底部已经被看到,这可以简化为

function isSeen(el) {
  return el.getBoundingClientRect().bottom <= window.innerHeight
}

甚至是一行

const isSeen = el => el.getBoundingClientRect().bottom <= window.innerHeight
9 年前
回复了 Community Fernando Kosh 创建的主题 » 如何在python子进程中运行bash函数?[复制品]

你需要设置 shell 关键字为true:

call("myAlias", shell=True)

从 relevant documentation :

如果 壳 是 True ,指定的命令将通过shell执行。如果您主要将python用于它在大多数系统shell上提供的增强控制流,并且仍然希望访问其他shell功能(如文件名通配符、shell管道和环境变量扩展),那么这将非常有用。

别名是shell特性(例如,它们由shell定义和解释)。

但是,shell(/bin/sh)是非交互执行的,因此没有 .profile 或 .bashrc 文件已被读取,您的别名可能不可用。

如果不愿意在python脚本中使用完全扩展的命令,则必须使用 $ENV environment variable 要使shell读取其中定义了别名的文件,请执行以下操作:

call("myAlias", shell=True, env=dict(ENV='/path/to/aliasfile'))