是否有可能顯示和隱藏像從div1到div5 mousedown()滾動樣式的div? 我剛剛開發了一個向下滾動的功能。這工作正常。 我們可以改變這個功能來顯示div1,div2 ....當mousedown()
viseversa爲mouseup()
?JQuery如何顯示,隱藏像滾動mousedown()和mouseup()
的事情是,只顯示在一個時間
這裏一個格是我目前的jQuery代碼
$(document).ready(function() {
var mouseisdown = false;
$('.up').mousedown(function(event) {
mouseisdown = true;
var topVal = $(".content").css("top").replace(/[^-\d\.]/g, ''); //remove the px from the current top val
topVal = parseInt(topVal);
console.log(topVal);
if(topVal < 0){ //This is to stop it when it reaches the top
$('.up').parents(".container").find(".content").stop().animate({"top":topVal + 20 + 'px'},'slow');
if (mouseisdown)
setTimeout(ScrollUp, 400);
}
}).mouseup(function(event) {
mouseisdown = false;
});
$('.dn').mousedown(function() {
mouseisdown = true;
var topVal = $(".content").css("top").replace(/[^-\d\.]/g, '');
topVal = parseInt(topVal);
console.log($(".content").height()+ " " + topVal);
if(Math.abs(topVal) < ($(".content").height() - $(".container").height() + 60)){ //This is to limit the bottom of the scrolling - add extra to compensate for issues
$('.up').parents(".container").find(".content").stop().animate({"top":topVal - 20 + 'px'},'slow');
if (mouseisdown)
setTimeout(ScrollDown, 400);
}
}).mouseup(function() {
mouseisdown = false;
});
});
CSS
div.container {
overflow:hidden;
width:250px;
height:200px;
zoom: 1; /* IE7 Fix - doesnt work */
}
div.content {
position:relative;
top:0;
left: 110px; /*this is for demo - it cuts off the text */
zoom: 1; /* IE7 Fix - doesnt work */
clear:bothl;
}
.up, .dn{
border:1px solid orange;
cursor: pointer;
}
.up:hover, .dn:hover{
background-color:yellow;
}
HTML
<div class="container">
<button class="up">Up</button>
<button class="dn">Down</button>
<hr style="clear:both;"/>
<div class="content">
<div id="div1"><p>Dolore magna aliquam erat volutpat.</p><p> Suscipit lobortis nisl ut aliquip ex ea consequat.</p></div>
<div id="div1"><p>Suscipit lobortis nisl ut aliquip ex</p><p> ea commodo Dolore magna aliquam erat volutpat.</p></div>
<div id="div1"><p>Dolore magna aliquam erat volutpat.</p><p>Suscipit lobortis nisl ut aliquip ex ea consequat.</p></div>
</div>
</div>
需要顯示在這裏顯示很多我們可以看到。我需要一次只顯示一個div similar
該id應該是唯一的,因爲JavaScript應該使用它來選擇DOM中的元素進行操作並在CSS選擇器中使用。 – antonjs 2012-03-28 14:25:45