javascript - 未启用 tinyScroll

标签 javascript jquery css jquery-plugins scroll

我正在尝试使用 tinyscrollbar 插件 http://baijs.nl/tinyscrollbar/

像这样:

$('#nvl2 .content').html( '<div class="scrollbar">'+
                                        '<div class="track">'+
                                            '<div class="thumb"><div class="end"></div></div>'+
                                        '</div>'+
                                  '</div>'+
                                  '<div class="viewport">'+
                                        '<div class="overview">' +$('#nvl2 .content').html()+'</div>'+
                                   '</div></div>'   ).attr('id','sc2');

                $('#sc2').tinyscrollbar();

这是在加载#nvl2 中的新内容的 ajax 调用之前调用的,但未启用 tinyscroll 并且 firebug 不会跳转任何错误

CSS:

/**************/
/* Tiny Scrollbar */
#nvl1 {   }
#nvl1 .viewport { ¡overflow: hidden; position: relative; width:100% }
#nvl1 .overview { list-style: none; position: absolute; left: 0; top: 0; padding: 0; margin: 0; }
#nvl1 .scrollbar{ background: transparent url(../images/bg-scrollbar-track-y.png) no-repeat 0 0; position: relative; background-position: 0 0; float: right; width: 15px; }
#nvl1 .track { background: transparent url(../images/bg-scrollbar-trackend-y.png) no-repeat 0 100%; height: 100%; width:13px; position: relative; padding: 0 1px; }
#nvl1 .thumb { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 100%; height: 20px; width: 25px; cursor: pointer; overflow: hidden; position: absolute; top: 0; left: -5px; }
#nvl1 .thumb .end { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 0; overflow: hidden; height: 5px; width: 25px; }
#nvl1 .disable { display: none; }

/**************/
/* Tiny Scrollbar */
#nvl2{   }
#nvl2 .viewport { ¡overflow: hidden; position: relative; width:100% }
#nvl2 .overview { list-style: none; position: absolute; left: 0; top: 0; padding: 0; margin: 0; }
#nvl2 .scrollbar{ background: transparent url(../images/bg-scrollbar-track-y.png) no-repeat 0 0; position: relative; background-position: 0 0; float: right; width: 15px; }
#nvl2 .track { background: transparent url(../images/bg-scrollbar-trackend-y.png) no-repeat 0 100%; height: 100%; width:13px; position: relative; padding: 0 1px; }
#nvl2 .thumb { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 100%; height: 20px; width: 25px; cursor: pointer; overflow: hidden; position: absolute; top: 0; left: -5px; }
#nvl2 .thumb .end { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 0; overflow: hidden; height: 5px; width: 25px; }
#nvl2 .disable { display: none; }

这是 ajax 调用完成后的内容示例

<div class="level" id="nvl2" style="left: 540px; display: block; height: 663px; z-index: 1;">
    <div class="content" style="display: block;">
        <div class="scrollbar">
            <div class="track">
                <div class="thumb">
                    <div class="end">
                    </div>
                </div>
            </div>
        </div>
        <div class="viewport">
            <div class="overview">
                <span class="close"></span>
                <div class="contentHeader">
                    <div class="contentHeaderImg">
                        <img alt="redLevel" class="attributeImgLogo" src="img/cnt/redLevel.png">
                    </div>
                    <h2>Red Level Glove</h2>
                    <h4>The boutique hotel within the hotel</h4>
                </div>
                <div class="contentImg">
                    <img class="attributeImg" alt="drink" src="img/cnt/redLevelDrink.jpg">
                </div>
                <div class="contentTxt">
                    <p>
                        Red Level Lounge: Exclusive VIP Red Level Lounge featuring private check-in with a welcome glass of Veuve Clicquot Grande Dame champagne.
                    </p>
                    <p>
                        The Red Level Family Concierge experience is offered in select resort locations. Luxuries include separate VIP check-in lounge exclusively for Family Concierge clients, designated family pools, premium suite accommodations designed with families in mind, upgraded ensuite amenities.
                    </p>
                </div>
            </div>
        </div>
    </div>
    <div class="extra" style="width: 418px;">
    </div>
</div>

在 ajax 调用和 tinyscrollbar init 执行之前:

<div class="level" id="nvl2" style="left: 540px; display: block; height: 663px; z-index: 1;">
        <div class="content" style="display: block;">
                    <span class="close"></span>
                    <div class="contentHeader">
                        <div class="contentHeaderImg">
                            <img alt="redLevel" class="attributeImgLogo" src="img/cnt/redLevel.png">
                        </div>
                        <h2>Red Level Glove</h2>
                        <h4>The boutique hotel within the hotel</h4>
                    </div>
                    <div class="contentImg">
                        <img class="attributeImg" alt="drink" src="img/cnt/redLevelDrink.jpg">
                    </div>
                    <div class="contentTxt">
                        <p>
                            Red Level Lounge: Exclusive VIP Red Level Lounge featuring private check-in with a welcome glass of Veuve Clicquot Grande Dame champagne.
                        </p>
                        <p>
                            The Red Level Family Concierge experience is offered in select resort locations. Luxuries include separate VIP check-in lounge exclusively for Family Concierge clients, designated family pools, premium suite accommodations designed with families in mind, upgraded ensuite amenities.
                        </p>
                    </div>
                </div>

        <div class="extra" style="width: 418px;">
        </div>
    </div>

可以在这里测试:http://toniweb.us/gm知道我错过了什么吗?

最佳答案

你是什么意思

...).attr('sc2');

在你的代码中? 带有一个参数的函数 .attr() 是属性值的 getter。你想为元素设置id吗?如果这是您的想法,那么更好的方法是将此 ID 插入此 html 代码:

<div id="sc2" class="scrollbar">

当执行与 tinyScrollbar 初始化一致时,在您的页面上:

$('#sc2').tinyscrollbar();

没有 ID 为“sc2”的元素,这就是滚动条未显示且在 firebug 中没有错误的原因。

关于javascript - 未启用 tinyScroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8578745/

相关文章:

javascript - 避免乱七八糟的浏览器死亡

javascript - Google map 主题是否有更好的代码结构?

java - 如何使用 JSF outputStylesheet 实现 CSS Cache Busting?

javascript - 如何将 CSS 文件导入到 webpack 中?

html - 使单个字符的 css 样式站点变宽?

javascript - 在 IE11 中通过 css() 缓慢进行 jQuery 导航重新定位

javascript - 是否可以在模式按钮中短暂存储表单数据?

javascript - 注销时jQuery清除缓存

jquery - 如何获取原始输入属性

javascript - 将事件处理程序添加到构造函数方法