我跟着jQuery.NiceScroll来编辑滚动条。通常,当我调用时$(selector).niceScroll()
,它会将一些 css 属性附加tabindex
到选择器中。像这样:
$('p.lead').niceScroll({autohidemode: false});
然后,id 开头的 2 个 div 也ascrail
将附加到<body>
。
如您所见:如果tabindex
is 5000
,则 2 个新 id 将是ascrail2000
and ascrail2000-hr
。
这意味着我们可以<div>
通过以下方式访问 's:
var id = 2000 + (+$('p.lead').prop('tabindex') - 5000);
var vertical = $('div#ascrail' + id);
var horizontal = $('div#ascrail' + id + '-hr');
//do stuff...
这很好,直到我使用jQuery BlockUI将一些 div 显示为弹出窗口:
<div class="new-topic">
<!-- another divs -->
<div id="tab-content5" class="tab-content">
<div class="n-images">
</div>
</div>
<!-- another divs -->
</div>
脚本:
$.blockUI({
message: $('div.new-topic'),
css: {
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
border: 'none',
cursor: 'default',
borderRadius: '5px',
width: ''
}
});
$('div.n-images').niceScroll({autohidemode: false});
然后,我查看了页面源,tabindex
被覆盖:
但这不适合div[id^="ascrail"]
:
现在,如何更改andz-index
中的css 属性?div#ascrail2001
div#ascrail2001-hr
这种方式将无法正常工作:
//this will return 2000 instead of 2001
var id = 2000 + (+$('div.n-images').prop('tabindex') - 5000);
//if I can get the id correctly, every thing will became easy:
//change z-index: auto -> z-index: 10001
//because if z-index is smaller than 10000, it won't appear
$('div#ascrail' + id).css('z-index', 10001);
$('div#ascrail' + id + '-hr').css('z-index', 10001);
我的问题是:$(selector).niceScroll()
没有检查现有的 tabindex 值并更新新的 tabindex 值。(现有值:5000,新值:5001)。
所以,我的问题是:在这种情况下如何更新 tabindex 的新值?
p/s:我正在使用 mvc 5。<p class="lead">
在另一个与<div class="n-images">
.