简体   繁体   English

Jscrollpane和内部锚链接

[英]Jscrollpane and internal anchor links

I am using Jscrollpane and everything works great, except when I try to use it with an internal anchor. 我正在使用Jscrollpane,并且一切正常,除非我尝试将其与内部锚一起使用。 It should work like the example on the official page. 它应该像官方页面上的示例一样工作。

But in my example it really destroys my site. 但是在我的示例中,它确实破坏了我的网站。 The whole content is floating upwards and I can't figure it out myself. 整个内容是向上浮动的,我自己也无法弄清楚。

Here is my page: http://kunden.kunstrasen.at/htmltriest/index.php?site=dieanreise&user_lang=de and if the inner anchor is clicked: http://kunden.kunstrasen.at/htmltriest/index.php?site=dieanreise&user_lang=de#westautobahn 这是我的页面: http : //kunden.kunstrasen.at/htmltriest/index.php? site= dieanreise& user_lang=de ,如果单击了内部锚点: http : //kunden.kunstrasen.at/htmltriest/index.php?网站= dieanreise&user_lang = DE#westautobahn

Anybody a clou whats going on here? 有人clou这是怎么回事? Thanks for your help. 谢谢你的帮助。

jspane does not work with old style anchors eg jspane不适用于旧式锚点,例如

<a name="anchor"></a>

instead you have to write 相反,你必须写

<a id="anchor"></a>

additionaly you have to enable 另外,您必须启用

hijackInternalLinks: true;

in jScrollPane settings Object. 在jScrollPane设置对象中。

The hijackInternalLinks also captures links from outside the scrollpane, if you only need internal links you can add this code, like hijackInternalLinks it binds the click funktion on the a elements and calls the scrollToElement with the target: hijackInternalLinks还会从滚动窗格外部捕获链接,如果只需要内部链接,则可以添加此代码,例如hijackInternalLinks,它将绑定a元素上的点击功能,并使用目标调用scrollToElement:

            \$(document).ready(function() {
            panes = \$(".scroll");
            //hijackInternalLinks: true;
            panes.jScrollPane({
            });
            panes.each(function(i,obj){
                var pane = \$(obj);
                var api = pane.data('jsp');
                var links = pane.find("a");
                links.bind('click', function() {
                    var uriParts = this.href.split('#');
                    if (uriParts.length == 2) {
                        var target = '#' + uriParts[1];
                        try{
                            api.scrollToElement(target, true);
                        }catch(e){
                            alert(e);
                        }
                        return false;
                    }
                });
            });
        });

but note you will always have to use the id attribute on a tags. 但请注意,您将始终必须在标签上使用id属性。 If you are using tinymce you can repair the code with this function 如果您使用tinymce,则可以使用此功能修复代码

function myCustomCleanup(type, value) {
    switch (type) {
            case "get_from_editor_dom":
                    var as = value.getElementsByTagName("a");
                    for(var i=0; i< as.length;i++){
                        if (as[i].hasAttribute('name')){
                            var name = as[i].getAttribute('name');
                            as[i].setAttribute('id',name);
                        }
                    }
                    break;
    }

    return value;

} }

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

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