简体   繁体   English

自定义iframe滚动条

[英]Customize scrollbars for iframe

I was wondering if is possible to customize the scrollbars for an iframe. 我想知道是否可以自定义iframe的滚动条。 Both the iframe and the page are on the same domain so there are no issues there. iframe和页面都在同一个域中,因此那里没有问题。 If so, what route should I take and is this something that I should be doing? 如果是这样,我应该走什么路线,这是我应该做的事情吗? (design-wise). (设计明智)。

I will be updating this as I get it working. 我将在工作时对其进行更新。 Just thought I'd try to get some insight ahead of time. 只是想我会尽早获得一些见识。

Thanks 谢谢

Okay, I ended up getting it working using jScrollPane . 好的,我最终使用jScrollPane使其开始工作。 The only hangup I had was that jquery.jscrollpane.css needed to be inside each iframe, not outside, which makes sense. 我唯一遇到的麻烦是jquery.jscrollpane.css必须位于每个iframe中,而不是外部,这很有意义。

Afterwards, all it took was 之后,只需要

$("iframe").each(function(){
    var body = $("body",this.contentWindow.document) ;
    body.jScrollPane();
});

where the above javascript is present in the parent of the iframe. iframe的父级中存在上述javascript的位置。 The jScrollPane js files are also in the parent, not each individual iframe. jScrollPane js文件也位于父级中,而不是每个单独的iframe中。

Afterwards, the scrollbars are sticky. 之后,滚动条便会发粘。 I solved this by covering the iframe in an invisible element after the scrollbar is clicked and uncovering when released. 通过在单击滚动条后将i​​frame覆盖在不可见的元素中,并在释放时将其隐藏,我解决了这一问题。 This was done by 这是由

$(".jspDrag",body).on('mousedown',cover_iframes);
$("body").on('mouseup',uncover_iframes);

where cover_iframes and uncover_iframes call the .show() and .hide() of the covering element, respectively. 其中cover_iframes和uncover_iframes分别调用coverage元素的.show()和.hide()。

Now I noticed that when the scrollbar is moved, it is shifted over by the offset of the iframe. 现在我注意到,当滚动条移动时,它会移动iframe的偏移量。 I am working on fixing that now. 我正在努力解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM