Comments (4)
参照本地运行的 http://127.0.0.1:9000/render.html
界面,是可以点击滚动的。
from vditor.
我打了一个外部的补丁,成功实现了预期的功能。
我采用了 vue ,在编辑器的元素上,监听事件 @pointerdown="clickEditor"
clickEditor(ev: PointerEvent) {
const el = ev.target as HTMLElement
const el_outline_item = findThisOrAncestor(el, '[data-target-id]')
// warn('el_outline_item', el_outline_item)
if (el_outline_item) {
const outline_item_target_id = el_outline_item.getAttribute('data-target-id')!
const el_target = document.getElementById(outline_item_target_id)!
el_target.scrollIntoView()
}
},
/**
* 从`el`开始向上(祖先元素)遍历,返回匹配`selector`的第一个元素
*/
export function findThisOrAncestor(el: HTMLElement | null, selector: string) {
while (el) {
if (el.matches(selector)) {
return el
}
else {
el = el.parentElement
}
}
return null
}
from vditor.
我也遇到了同样的问题。
我是参照 demo 的代码,调用了一个选项参数最简单的实例。
其它功能都很正常,只有大纲点击无效。
from vditor.
我查看了一下源代码。
在文件 'src\ts\markdown\outlineRender.ts' 中,找到小标题元素 idElement
后,要滚动到它。
这个工作,按理说,用一行代码即可实现:
idElement.scrollIntoView()
不知为何(也许是为了兼容古老的浏览器?),源代码中的实现非常复杂。
可能就是在其中发生了错误。
相关部分如下。
if (target.classList.contains("vditor-outline__action")) {
...
} else if (target.getAttribute("data-target-id")) {
event.preventDefault();
event.stopPropagation();
const idElement = document.getElementById(target.getAttribute("data-target-id"));
if (!idElement) {
return;
}
if (vditor) {
if (vditor.options.height === "auto") {
let windowScrollY = idElement.offsetTop + vditor.element.offsetTop;
if (!vditor.options.toolbarConfig.pin) {
windowScrollY += vditor.toolbar.element.offsetHeight;
}
window.scrollTo(window.scrollX, windowScrollY);
} else {
if (vditor.element.offsetTop < window.scrollY) {
window.scrollTo(window.scrollX, vditor.element.offsetTop);
}
if (vditor.preview.element.contains(contentElement)) {
contentElement.parentElement.scrollTop = idElement.offsetTop;
} else {
contentElement.scrollTop = idElement.offsetTop;
}
}
} else {
window.scrollTo(window.scrollX, idElement.offsetTop);
}
break;
}
from vditor.
Related Issues (20)
- 在分屏预览模式下,linkToImgUrl方法不会触发 HOT 2
- 内容为空时回车禁止光标跳动 HOT 2
- `insertValue` 后无法回车 HOT 2
- IR 模式滚动时隐藏代码块语言提示 HOT 2
- 目录导出 HOT 2
- 在即时渲染模式中,无法删除无序列表中出现的空行 HOT 3
- 即时渲染模式下,在无序列表中,img标签的显示规则不一致 HOT 3
- 粘贴网页图片,不能触发upload.linkToImgCallback回调 HOT 1
- 调用toolbar操作栏Api HOT 1
- 请教一下一个组件能否同时支持渲染多种格式的内容
- mermaid 图表渲染自适应 HOT 3
- 改进松散列表的展现
- 为什么代码块渲染时会出现两次复制的情况,一次在外面,一次是里面的代码块折叠 HOT 1
- 编辑 Latex 公式时,能否把编辑区域改到公式的右侧和下侧? HOT 1
- i18n的js加载异常,net::ERR_ABORTED 404 (Not Found)
- 不支持图片粘贴上传?,please config: options.upload.ur HOT 1
- 改进 bilibili 视频网站解析
- 添加 `preview.render.media.enable` 参数
- Compiled with problems HOT 1
- Markdown粘贴过去的普通链接可否自动渲染成可以点击的超链接 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vditor.