我想要实现的是在设定高度之后相对简单我想要使用Bootstrap默认属性来折叠div。下面我写了一个javascript,在设定的高度后触发,但我不确定的是如何触发id为#more
的崩溃。
function testScroll(ev) {
if (window.pageYOffset > 1100) alert('User has scrolled at least 400 px!');
}
<div id="more" class="collapse">test</div>
答案 0 :(得分:1)
您可以使用引导文档中定义的collapse function,为其提供元素ID。您还可以阅读更多相关信息here。
function testScroll(ev){
if(window.pageYOffset>1100) {
alert('User has scrolled at least 400 px!');
$('more').collapse('hide');
} else {
alert('User has not scrolled at least 400 px!');
$('more').collapse('show');
}
}
<div id="more" class="collapse">test</div>
答案 1 :(得分:0)
如果我理解您不知道如何选择和更改项#more
的类别
var collapse = function() {
// select the element that has the id #more
var element = document.getElementById('more');
// now you can, for exemple change its class
// that's where you can apply a different css class to collapse the div
element.setAttribute('class','anotherClass');
}