我的html中有这个div:
<div class="row-fluid container-nav" data-spy="affix" data-offset-top="130">
<div class="container">
<div class="row-fluid">
<?php nav_menu_primary(); ?>
</div>
</div>
</div>我需要将data-spy="affix“更改为data-spy=”affix top“,以便在媒体屏幕较小时导航不会在顶部粘滞。
JS:
$(window).resize(function() {
// if screen is resize
delay(function() {
var width = $(window).width();
// document.write(width);
if( width >= 550 && width <= 767 ) {
$('.toopnav').css('data-spy','affix-top');
}
}, pause );
});
$(window).resize();发布于 2013-10-21 14:23:12
将.css()更改为.attr()
$('.toopnav').attr('data-spy','affix-top');或者使用更好的方法.data()
$('.toopnav').data('spy','affix-top');发布于 2013-10-21 14:24:47
使用jquery data属性..这就是为什么在最新版本jquery中引入了jquery.data。
$('.toopnav').data('spy','affix-top');根据你的html,我想应该是
$('.container-nav').data('spy','affix-top');https://stackoverflow.com/questions/19487512
复制相似问题